awk is a special-purpose, interpreted programming language for extracting and reporting data.

learn more… | top users | synonyms

5
votes
4answers
491 views

how to delete line numbers in a code block?

Generally codes published in web pages contains line numbers. When I copy and paste code into text editor (though some text editors remove line numbers automatically, but somtimes it doesn't work), it ...
0
votes
1answer
32 views

Linux : Data extraction from text file

I have a text file in which thousands of data is there. eg. id=row_value profile=row_value name=row_value email=row_value address=row_value id=row_value2 profile=row_value2 name=row_value2 ...
0
votes
1answer
52 views

return value from awk

This is mybashfile.sh file . . . awk -f myawkfile.awk mytracefile.tr . . . Now I want to return one parameter from myawkfile.awk to the current mybashfile.sh. Is there any way to return a value ...
2
votes
2answers
33 views

access to field's element via awk

I have the following columns: _111_ [555] _222_ [666] _333_ [777] _444_ [888] I want to access the 111 from _111_. or 888 from [888]. How to access the fields elements with awk.
0
votes
1answer
65 views

access to column in python like awk [closed]

This is my data file: Iam python newbie If I use awk to access columns element, that is easy just by $1. how can I access this columns element on python?
0
votes
1answer
41 views

one column from output column on awk

Suppose which I have this table: one two three four two three four five three four five six four five six seven five six seven eight so I wrote awk -v word=two '$0 ~ "[^[:alpha:]]" word ...
3
votes
2answers
237 views

Find a word using AWK

Is there a way to find a specific record among the whole line? This is my file: one two three four two three four five three four five six four five six seven five six seven eight How do I search ...
2
votes
1answer
27 views

How to print all coloumns using AWK

In AWK, is there a way to print all columns? I do not want to print them like this: printf($1 $2 $3 ...) Is there a way to print all of them?
0
votes
2answers
47 views

awk search help [closed]

I need help with a simple awk script for matching letters on a lines. For example, Finding separate matches for KJ in one field and finding matches for KP in the next? Name VT Kip ...
0
votes
1answer
27 views

How to filter grep results?

I am new at writing scripts. So I am hoping this is simple. The script I am writing is used to gather system information and save it as an html file. When I run: sudo lshw -short it list all of ...
0
votes
1answer
127 views

New PHP5.3.10 update error

After receiving the latest announcement about security vulnerabilities of PHP5 (Ubuntu Security Notice USN-2254-1) I decided to upgrade my server, but I ran into some problems. The new packages listed ...
1
vote
1answer
136 views

using awk to print variable in loop

I am beginner in working with bash script. I have a data file: i z r 0 -30 3.5 0 -29.5 3.4 0 -29 3.6 ... ...
0
votes
1answer
40 views

Can someone explain what this grep/cut/awk command is doing

This is inside of a .sh script file: cd /somefolder IP=$(ifconfig | grep 'inet addr:'| grep 168 | grep 192|cut -d: -f2 | awk '{print $1}') The /somefolder has another folder list with a single ...
0
votes
2answers
75 views

Speed up script

Which shell command is the fastest way to parse through millions of lines of text. Currently I'm using GREP in my script but it takes hours upon hours to finish. Sample Input: May 1 2014 00:00:00 ...
1
vote
3answers
36 views

Document Sorting Section

I have some sample data below (call it test.txt). I would like to split this big document into 3 documents by searching the first two digits in the 4th column. I'm pretty new with Linux (Lubuntu ...
4
votes
3answers
970 views

Awk command to print all the lines except the last three lines

I want to print all the lines except the last three lines from the input through awk only. Please note that my file contains n number of lines. For example, file.txt contains, foo bar foobar barfoo ...
1
vote
1answer
61 views

Why does using double quotes to enclose awk's action statements produce different results than when using single quotes to enclose them?

If I use single quotes to enclose awk's action statement, it works as expected: $ dpkg -l | grep "linux\-[a-z]*\-" | awk {'print $2'} linux-headers-3.13.0-27 linux-headers-3.13.0-27-generic ...
2
votes
2answers
48 views

How to correctly invoke awk in Perl to print out the 3rd last field in a line?

My script is: #!/usr/bin/perl -w my $line="1 2 3 4 5 6 7"; print $line; my $thirdlast=`print $line |awk '{print $(NF-3)}'`; print $thirdlast; The output is: 1 2 3 4 5 6 7 awk: 0602-542 There is ...
0
votes
3answers
131 views

How can I extract user data from a file with awk and create a new user based on it?

I need somebody who could help an exercise. I can only use shell scripting and awk to do it: You have a text file called users.txt with this info inside: users.txt: Peter:7777:/home/store ; ...
3
votes
4answers
393 views

Find files with a specific 2-line pattern using awk

I have a few hundreds of files that has this pattern @<TRIPOS>ATOM 2 H18 65.2220 Du 1 RES1 0.0000 @<TRIPOS>BOND 1 3 5 ar @<TRIPOS>SUBSTRUCTURE among them, some of the files ...
1
vote
1answer
623 views

How to pass string variable as parameter to awk

I have following command: usb_soundcard_sink=$(pactl list short sinks | grep "alsa_output" | awk '{ print $2 }' | tail -n1) output of this command is: alsa_output.pci-0000_00_1b.0.analog-stereo ...
0
votes
3answers
80 views

Awk scripting help

Hey guys new to scripting and looking to see why I get the following error message: syntax error near unexpected token '$0' using this .sh file to rearrange date and time in a .txt file so that ...
1
vote
1answer
144 views

How to copy a part of a line to another position

I have about 100 print statements in a file like this: printf("%f \n\n",row1.req_pnttime); I want to copy the variable name inside the string so that it becomes like this ...
1
vote
2answers
52 views

Grab a field without a fixed position via awk

I'm working on a script to wake different LCs on my LAN. MAC-Adresses are hard to memorize so I made myself a list that contains information about the respective PCs. Right now the list looks like: ...
4
votes
2answers
131 views

Using Regex Breaking a text on the last digit using linux tools like sed, or awk

I have the following list that I want to break on the digit. For example: From: 103Ru 103mRh 104 1041 To: 103 Ru 103 mRh 104 1041 I would like to use Regx with sed or maybe awk in order to ...
4
votes
3answers
2k views

How can I process multi-line records with awk in a bash script?

example.txt is below Restaurant: McDonalds City: Miami State: Florida Address: 123 Biscayne Blvd Phone: 911 Restaurant: 5 guys City: Atlanta State: Georgia Address: 123 Peachtree Rd Phone: 911 ...
1
vote
1answer
594 views

split string with awk and delimiter

i have log file like : 1:: 10:: 127.0.0.1 172.17.1.1 i want awk to split string to columns on :: delimiter. some thing like : awk {print$1} and the result : 1 and awk {print$2} and the ...
1
vote
2answers
73 views

how to trim dpkg upgraded packages list

Latest upgrade borked my system and I`m trying to revert the last upgrade. I opened my comp with live USB and chrooted to partition that is OS installed. I get the upgraded packages with cat ...
0
votes
1answer
152 views

sed, grep, and awk file sorting

I'm trying to get all the files which have 'load' in their names from a directory. I'm trying to do: find -type f | sed -s 'load However, I recurrently receive an error sed: -e expression #1, char ...
0
votes
1answer
113 views

Download AWK to Ubuntu

How to download awk to Ubuntu, since I tried to use asorti function and it told me that there is an error on this asorti. I tried many scripts that used asorti function and the same error occure!
0
votes
1answer
208 views

Syntax error in awk program

I want to check the method of IP-Assignment as in this question. I'm running it in bash on Ubuntu 12.04. My Problem is the function "get_con_id()" gives me "Syntax error" at the if-clause. The script ...
0
votes
1answer
109 views

Concatenation in Shell Scripting Bash

I wanna check if 2 lines have equal $4 my shell must check if the diffrence between $3 in line 2 and $2 in line 3 is equal 1 it must concatenate both line into one like this 1;1000000000;1099999999;2 ...
0
votes
1answer
29 views

Sort FileA into FileB while actively removing lines from FileA

I tried simplifying the title, apologies if it's somewhat confusing. I have a large text file (File A)(around 13GB) and I want to sort through it (into File B) to delete duplicate lines. Problem is I ...
-1
votes
2answers
100 views

Reading a file line by line

I have a file that looks like: @ATDGGSGDTSG NTCCCCC + nddhdhnadn @ATDGGSGDTSG NTCCCCC + nddhdhnadn Now its a repeating pattern of "4" lines and I every time want to print only the 2nd line i.e. the ...
0
votes
1answer
37 views

Formatting a file to use it with fortune in the terminal

I have a big text file with 'Terms' and its 'Definition' separated by spaces(variable). I want to use it in fortune cookie format. Current file format: **term1** this is my definition with ...
2
votes
3answers
143 views

Print multiple lines starting with “D” after multiple greps

I have two text files. Text-file-1 contains strings (one string per line); C 010 C 020 C 024 . . . Text-file-2 contains data in following format; C 005 Carbon D Carbon 1 D Carbon 2 D Carbon 3 D ...
9
votes
2answers
5k views

What does this command mean: awk -F: '{print $4}'?

Please explain what does following command mean: awk -F: '{print $4}'
2
votes
4answers
247 views

Using if an AWK command

I have a file which contains many sub-sections each starting with [begin] and ending with [end]sample of which is shown below: [begin li1_1378184738754_91] ...
2
votes
2answers
551 views

How to write an awk script that catch ping's time

In this line: Reply from 10.11.12.13 time=1035ms how to write an awk script which brings out just 1035.
2
votes
1answer
197 views

Subtitle Overlapping: How to comparing two timelines in subtitles (e.g. 00:18:06 vs 00:16:01) and overwriting one of them if it's overlapping?

I have a series of srt files (film subtitles) that some of their time-lines overlap each others on the video! This means that some of time-lines are displayed about 1-2 seconds longer than they are in ...
3
votes
2answers
198 views

How to batch organize files?

I have a directory with gigabytes (about 8gb) of small individual files. I want to organize them into directories by date. The date it was created is part of the filename. Here is an example of a ...
1
vote
1answer
53 views

Skip records containing no field separator in awk

In awk, I am using / as the field separator. However,there are some records in the input file that do not contain this field separator. How does awk behave for such records? Is there any way to tell ...
1
vote
2answers
2k views

awk programming - Changing a field value conditionally

I'm a beginner in awk programming. This post is to clarify a doubt. I have file like this: 70 17 5 mb 71 18 6 ms 72 19 7 ml 73 20 8 mw in which 4th column is a string. I want to make changes in the ...
1
vote
0answers
134 views

Grep word in one file, and use that word to match in another file, adding the thing that follows the match [closed]

I want to grep several words in file1, and use each word to grep what follows after its match in file2. And then I want to add the thing that followed the match to the word I used into file03, so that ...
3
votes
1answer
231 views

Why doesn't this command work as an alias?

I've been using the following command to list the ten largest files, at any depth, under the current directory: find -type f -size +10M -exec ls -gGsSh1 {} + | awk 'NR<=10 {print $0}' (I use awk ...
4
votes
2answers
231 views

Print text file every three line start at 2nd line

I have done it with simple loop to count and print through.. How can I do it in bash scripting with program such as sed,awk ?
2
votes
2answers
143 views

Help using Awk to change a file

I am using awk to simply change some text in a file, while maintaining the values as they are currently in the file. The problem is a few of the values are changing. the values are maintained if i ...
2
votes
1answer
149 views

Need help in SED and AWK

I have a file "list" as following: main.c getname 25 main.c getage 36 util.c namecheck 123 The above has first string file name, second function name, and third line no. I want to: Open the ...
2
votes
1answer
112 views

awk quoting program text

I just came across a gotcha in awk, and I would like to know if anyone can explain to me why this happens. The following 2 lines behave differently if I run: # grep -Rl BASE_DIR --exclude-dir=.svn * ...
2
votes
5answers
387 views

sed/awk make lines starting with lower characters be merged to previous line

Here is what I have This is a sample text How to do it ? I need the output to be: This is a sample text How to do it ? In addition, how can I achieve the same with: This is a sample text How ...