awk - pattern-directed scanning and processing language

learn more… | top users | synonyms

1
vote
1answer
57 views

AWK: Nested Conditional Subset of Rows

I have a pretty specific question, and have been able to find lots on conditional subsetting using awk but none that lends enough explicit code for me to generalize to my situation. I have a file ...
1
vote
5answers
111 views

Use SED or AWK to move string to new column and row

I have a .csv file that is tab delimited and I need to move the header row information to a "new" column at the beginning and a specified numbers of rows down. Please forgive any formatting errors for ...
1
vote
2answers
74 views

Compare set of values from two files and print the output in third file in awk

Hi friends i have problem with comparing two files.I'll try my best to explain.I have two file f1 and f2 which i have to compare on basis of two sets Parameter(p) and Value(v). Basically f1 contains ...
2
votes
3answers
134 views

How to replace the content of specific column with awk?

Given there is 40 columns in a record. I want to replace 35th column so that the 35th column will be replace with the content of 35th column and a "$" symbol. What came up my mind is like: awk ...
1
vote
3answers
145 views

GREP / SED or AWK: Print entire paragraph in a file on pattern match

I have a file with hundreds of paragraphs of around 15 lines each. I need to search for a pattern, say Occurance: 1. If this pattern is found in the para, I need to print the entire paragraph. Note ...
1
vote
4answers
1k views

Using sed/awk to remove anything after first space

aaaaaaaa 09 bbbbbbbb 90 ccccccccccccccc 89 ddddd 09 Using sed/awk/replace, in the above text I want to remove anything that comes after the first space in each line. For example the output ...
6
votes
6answers
78 views

How can I avoid escaped delimiter characters in a Unix command?

I need to take the sum of a field which is tilde (~) delimited. Problem I have is that my data is also having delimiter escaped. Example 1~CEO~ashok\~kumar~1000 As we see in 3rd field above we ...
1
vote
3answers
37 views

Shell command to remove the first string that is enclosed with slashes

I need a shell command(sed or awk is preferred) to remove the string that is enclosed within the slashes. For example If my string is /some/dir/example/ then the output should be dir/example/
5
votes
2answers
95 views

How would I add a prefix to input I receive from a pipe via awk and color the prefix conditionally?

Is there a way to add a prefix to lines received (and filtered) via awk - yes I know that's possible so far - and then conditionally (e.g. based on the existence of the $PS1 variable of the ...
4
votes
3answers
335 views

awk command for parsing a file

I have a following text file. I am showing you the first 3 lines. chrom st end gene strand c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 chr6 3345 3543 geneA + 36 -23 ...
4
votes
4answers
109 views

Combine fdisk and df in the same output

sudo fdisk -l gives : 255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size ...
2
votes
2answers
120 views

Extract file name from path in awk program

I have an awk script and I have passed a CSV file to it. awk -f script.awk /home/abc/imp/asgd.csv What am I doing is to get FILENAME within script.awk. FILENAME gives me the whole path. As I am in ...
4
votes
7answers
319 views

How can I groups numbers in a file

I have a file with numbers in float format. I can review them via sort -rn numbers.txt | less I would like though to be able to "group" them. I.e. easily see how many are in the same range. To give an ...
6
votes
4answers
7k views

Delete range of lines above pattern with sed (or awk)

I have the following code that will remove lines with the pattern banana and 2 lines after it: sed '/banana/I,+2 d' file So far, so good! But I need it to remove 2 lines before banana, but I can't ...
2
votes
2answers
109 views

how to parse a file that is changed continuously using awk?

for example if we have a file contains : Hello world Hello earth Hi everybody we can easily parse it to get the first and second columns of the lines contains the word Hello using awk: awk ...
5
votes
3answers
388 views

What are the exact differences between awk and cut with grep? [closed]

We know that we can get the second column of the line we want from a file using these two techniques: cat fileName | awk '/WORD/ { print $2 }' or cat fileName | grep WORD | cut -f 2 -d ' ' My ...
0
votes
1answer
235 views

two .csv files compare using awk

I need to compare two files, File1.csv and File2.csv (Separated by ',') using Awk Logic: Column PID in both files are reference. If for same 'PID' in 'File1.csv' and 'File2.csv' and in both files ...
3
votes
3answers
102 views

How can I get the first column of a 300GB txt file?

let me first explain my problem in detail. It's actually pretty simple. I have a huge .txt file, 300GB to be more preciese, and I would like to put all the distinct strings from the first column, that ...
3
votes
3answers
86 views

How to keep record of previous operation results in awk?

I ran into another challenge that I am completely stumped on. I have a file filled with data in the following format. There are 3 lines that need to stay together and they have a predictable pattern: ...
2
votes
3answers
87 views

can I make awk cut its input according to '\n'?

we all know that we can get the columns of a line using awk, but the columns is split by white spaces: cat FileName | awk ' { print $1,$2,$3 .... }' but what if we want to split the files according ...
5
votes
2answers
121 views

Use awk to insert a line after N output

I have a text file filled with a bunch of data. I need to pull out lines that contain specific strings. I accomplished this with awk using the following: awk '/pattern1|pattern2|pattern3/ {print;}' ...
0
votes
4answers
156 views

Search for a Value only in one column w.o using awk, sed, or perl

I have a file that looks like this : Marketing Ranjit Singh FULLEagles Dean Johnson Marketing Ken Whillans FULLEagles Karen Thompson Sales Peter RobertsonPARTGolden ...
0
votes
3answers
61 views

Compare three file and print the highest value

I have three files. All of them having only one column. File1 M 0 M A File2 A 0 M A File3 M 0 A A compare each row in the three files, i.e, for first row (M,A,M) hence the maximum occurrence is ...
1
vote
2answers
141 views

Compare two file and return a true or false value

I have two files with one column. If the first rows in the two files are same the print 1 otherwise print 0. file1: M A A M file2: M M A A output: 1 0 1 0 Can anybody tell me the awk script? ...
0
votes
4answers
46 views

compare columns in a one file and print the count of matches

I have a CSV file that contains two columns. I want to compare the two columns and print the number of matches. file1 M,M A,M A,A M,A Expected output: If the first columns in the first row is the ...
1
vote
3answers
54 views

awk one single line

hello i try to use a awk that compiles several lines into one, how can ia do that? i'm using the comand: awk < $pot/towhee.prod 'NR==411{print$5,$6}''NR==412{print$5,$6}''NR==430{print$7,$8}' ...
2
votes
1answer
58 views

Substite values from file1 to file2 awk

I have input file in xml FILE1 : <Sector sectorNumber="1"> <Cell cellNumber="1" cellCreated="YES" cellIdentity="" cellRange="35000" numberOfTxBranches="1" hsCodeResourceId="0"/> ...
2
votes
3answers
136 views

replace column of a csv file with column from another file

I have two sample files like this: $ cat file1 abc,sachin cat,kumar $ cat file2 xyz pressure $ cat file3 xyz,sachin pressure, kumar I want the first column of file1 to be replaced with file2. ...
0
votes
4answers
63 views

Print text between tags (inclusive) if certain text is found

I've got a task to extract data from several Apache servers. The task is to print out: <Directory ...> ... </Directory> where +ExecCGI is located within. Let me give an example to ...
3
votes
2answers
128 views

unix awk begin statement

I was trying to use a begin statement in awk, but somehow the begin statement is printed on top of every record instead of the very first record that I wanted. I am not very sure why, it would be ...
0
votes
1answer
83 views

Duplicate specific text in text file, using perl or grep

I need to duplicate part of a plain text file as follows: The text file consists of a sequence of "pages", of the form: <page [lots of lines of text] /page> <page [lots of ...
3
votes
2answers
75 views

how to grep complex hierarcy?

I have a file as:- start apple 1 a 2 b 3 c start orange 4 a 5 b start mango 1 a start a/b/c 5 z end 4 b end 6 c end start banana 3 c end 4 d 5 e end I want the output as :- 1 apple/a 2 apple/b 3 ...
-3
votes
1answer
149 views

how to select specific range of line & count the specific occurence of the first charcter w.r.t. each unique second charcter? [closed]

Hi I have a file like this : #0 0:() 1b:cg*b 1c 0:cg xe #4 0:() 0b:cg*b xc 0:cg 1e #8 0:() 0b:cg*b xc 0:cg xe #12 1b:cg*b xc 0:cg 0e #16 xb:cg*b 1c xe #20 1:() xb:cg*b xc 1:cg 1e #24 x:() xb:cg*b xc ...
2
votes
3answers
351 views

How to copy or read the return value (exit status) from AWK script into the shell script (bash) to be used in if statement to compare

I want to read the error codes or the exit status of awk script into shell to use in if condition to compare for error handling my shell script looks something like: My script: #!/bin/sh awk -v ...
4
votes
4answers
426 views

How to remove duplicate lines with awk whilst keeping empty lines?

Below awk command removes all duplicate lines as explained here: awk '!seen[$0]++' If the text contains empty lines, all but one empty line will be deleted. How can I keep all empty lines whilst ...
0
votes
2answers
57 views

Formatting numbers using awk / print

I found this very cool code to get upload/download speed: awk '{ if (l1) { print "↓"($2-l1)/1024"kB/s ","↑"($10-l2)/1024"kB/s" } else { l1=$2; l2=$10; } }' <(grep wlan0 ...
0
votes
1answer
50 views

change column with awk scriting

I am trying to make a script B that uses another script A to change a specific column in a specific line. The problem is that when I run the script A alone it runs perfectly but when I try to use the ...
2
votes
4answers
143 views

sed remove end of line for specific lines

I'm trying to find the sed command to remove the end of the line (meaning, get the next line to the current), but only if line starts with the string NOTOK. example input: NOTOK something ...
3
votes
6answers
351 views

Add a symbol before any letter

I have a text file with each line having some defined number of fields but they can differ from line to line. All I want to do is to add "=" sign in front of every value in the field in that line. ...
6
votes
5answers
8k views

Show sum of file sizes in directory listing

The Windows dir directory listing command has a line at the end showing the total amount of space taken up by the files listed. For example, dir *.exe shows all the .exe files in the current ...
1
vote
2answers
71 views

Renaming a whole folder content

I'm on OSX 10.9.2 (BASH 3.5) and I wanted to rename a whole folder content names. So I run a script and somehow ended with this: s01eDavid.Letterman.2014.02.27.Stupid.Human.Tricks.x264-SWOLLED.mp4 ...
-4
votes
1answer
115 views

Write a script file 'account.awk' that from a file 'orders' creates the formated printout of account

Write a script file account.awk that from a file orders creates the formatted printout of account. The file orders is as follows: http://pastebin.com/kPF5B0c0 Beside the column Cost the account ...
1
vote
4answers
225 views

Pattern Matching and Delete the whole line

I want to delete all the Lines of File 1, if Column1 of File1 matches exactly with Column 1 File2. File 1: r001:21:10 21 AAAAAATTTGC * = XM:21 r002:21:10 21 YAAAATTTGC * ...
1
vote
3answers
650 views

Delete lines from a file using awk or sed based on the variable from previous command

I have a CSV file (say temp.csv) with strings and numbers. I need to delete the lines which contain a particular pattern of string at the beginning of the lines in the file. For example, here is my ...
-2
votes
3answers
66 views

Can anyone please explain me below AWK script

format of flat file : ;metier_code ; ;-------------------------; (0 rows affected) ;CRDS_Ptf_No; ; ; ; ; ...
0
votes
3answers
85 views

Copying specific text from one file into a schema

I have two files. One being a schema, and the other a list of data. The schema looks like: line_name: shot_edit: channel edit: cable_edit and repeats regularly for the number of lines that I ...
3
votes
1answer
189 views

Fastest `uniq` tool in linux

I have large text file (1.5 G), I want to know what the fastest and more reliable tool in linux is. I usualy use: awk '!x[$0]++' file.txt But when I use htop command I see my memory usage is ...
2
votes
5answers
239 views

Can the string “abcedf” be matched to string “bafcde” in a single line command?

I am planning to implement an indexing structure in my program. For example, if I have 100 rows in the table, I will number these rows from 1 to 100 in another column by appending an _ to the end of ...
1
vote
1answer
39 views

Tile logfile into pieces and search for errors

I want to tile a logfile into pieces and then search in this pieces for errors. If there is an error, I want to put the relevant logfile-piece into another file. Little example: Logfile looks like ...
1
vote
2answers
91 views

How can I format a flat file using awk?

Below is the format of some table data contained within a single file: ;NULL;ABCD;ABHJARS;;ABCD;ABCD;Y;;;;;;;;;A; ;NULL;XEU-ANKD;XEU-AJKD;;ABCD;ABCD;Y;;;;;;;;;A; . . ;11744;AMKDIONSKH;AMKDJ AN DJ ...