awk - pattern-directed scanning and processing language

learn more… | top users | synonyms

2
votes
2answers
138 views

Awk: expanding first field along the column

I have a task which requires some awk scripting: Lets say I have a file: A,under1 ,under2 ,under3 ,under4 ,under5 B,new1 ,new2 ,new3 C,sm1 ,sm2 How could I make it look like this using awk? ...
0
votes
2answers
250 views

Errors when searching for special characters in awk

How can I search for a pattern in awk if the text contains special characters? billinAddress || when I search, it is showing an error on pipe sign ||. How can I search for the pipe sign || in awk? ...
2
votes
2answers
928 views

Data pivot with awk

I'm trying to pivot a file using awk. This is an example of my input File: VarName;TimeString;VarValue;Validity;Time_ms A;23.11.201215:03:53;1;1;41236627696,7593 ...
1
vote
1answer
422 views

Validate Unix Timestamp using BASH

My google-fu has failed me so I'm hoping someone here can point me in the right direction. I'm in the middle of doing some data validation efforts and I suspect the system is recording some invalid ...
3
votes
4answers
4k views

removing the first and the last character of every line from command line

I am trying to remove the first and the last characters of everyline in a text file and save the resulting truncated version in a new file. Does anyone have an idea about how to do that efficiently ...
0
votes
2answers
1k views

Replace matches with multiline string using sed [duplicate]

Possible Duplicate: Insert a multiline string into another string I have a file called foo.txt containing: foo bar baz I want to replace every occurence of bar with a multiline string, ...
1
vote
3answers
439 views

linux/solaris + verify duplicate valid IP address from file

what the best way to find duplicate IP from file ( I have ksh script in this script I need to write function that check for duplicate IP ) for example if IP - 192.1926.23.52 exists twice in file - ...
2
votes
1answer
970 views

Bash variable in Awk script

I have this flat file database(ff_servers.db) with following contents: 192.168.154.2 Alaska hp 192.168.157.3 Colorado dell 192.168.156.3 hawaii hp From command line, I could run: awk ...
3
votes
1answer
180 views

Are there awk versions that provide syntax for computing aggregations?

From time to time I find myself writing awk scripts that compute some simple statistics. For example computing a histogram, the average of a value, the standard deviation or even the variance ... ...
1
vote
1answer
173 views

Sed and Awk learning material [closed]

I'm looking for some learning material for sed and awk, can anyone make any suggestions? Please don’t refer to man and help pages. -O-
2
votes
1answer
203 views

Using awk, how to get desired output from multiple file sources

I have two files: file1: A,D B,E C,F file2: G,H,I J,K,L Using awk, I want to print: A,D B,E,I C,F,L How can I use awk to achieve this?
1
vote
1answer
104 views

how to add a description in footer

I enjoy learning how to modify files with awk, sed, and bash. However, I know it could cause issues down the road and I would like to be prepared with a log inside the file. I was thinking about how ...
0
votes
1answer
94 views

Why is this variable not getting passed to awk? [duplicate]

Possible Duplicate: external variable in awk How do I pass this variable below? This doesn't work: fname=testfile.txt lsof | awk '/deleted/&&/$fname/ {print $4}' *----no output* ...
1
vote
5answers
349 views

Replacing lines in files with file contents

I have several files which contain some PHP includes and I want to substitute them with the file contents. The file looks like foo <?php include("file1.php"); ?> bar baz <?php ...
9
votes
3answers
2k views

Process last line first using awk

I have a data file that I want to normalize using awk, based on the last datapoint. Therefor, I would like to access the last data point first, to normalize the data, then process normally. The ...
3
votes
3answers
1k views

How can I call bc from within awk in this case?

OK, so I love my awk, but yeah, it has precision issues, and unfortunately there's no easy way for me to install the multi-precision extensions known as gawkextlib. What I am doing is, I am working ...
2
votes
3answers
331 views

Awk to output read file

I havent stepped into awk yet but it is on my plate for learning this coming year. I asked a previous question that led me to awk and it works. However, I am unsure how to input all file types and ...
3
votes
1answer
883 views

Awk - how to compare two numbers?

This example works fine: awk -v num1=5999 -v num2=5999 'BEGIN{ print (num2==num1) ? "equal" : "not equal" }' equal This example does not work well: awk -v num1=59558711052462309110012 -v ...
0
votes
1answer
495 views

If Else in Gawk

I have an example: echo $(seq 9) | awk '{for(i=1;i<=NF;i++) if(i!=5&&i!=6) {printf "%s ",i}else{printf "%s ",""} print ""}' 1 2 3 4 7 8 9 Is it possible to use the shorthand of this ...
2
votes
2answers
611 views

print a file in hex using awk

I have a file name x $ cat x 1A34532112345 I wants to print in hex using awk I written a script (with help from web) fold -1 /home/cscape/Desktop/x | gawk '{ printf("%s , %X\n",$0, int($0) )}' ...
3
votes
1answer
316 views

Split file based on a pattern with leading zeros

I have a book in text format. I would like to split the book into several files where each file contains a single chapter. Therefore I'm using the following command: awk '/Chapter/{i++}{print > ...
0
votes
1answer
256 views

globbing, sed, or awk html files

I wanted to create a script that I could check .xhtml files for images and add alt tags if needed. While searching I found regular expressions and did man on glob but I'm unsure on where or what to ...
1
vote
2answers
102 views

Extra % in output of awk script

I have the following script in awk that sums all columns in a file that I pipe to it: #sum_all.awk { for (i=1; i<=NF; i++) { sum[i]+= $i } } END { for (i=1; i<=NF; i++ ) { printf "%d ", ...
2
votes
3answers
514 views

Merging content of two files with comparing content of column

I have a problem trying to merge content of two files : file 1 : 873 1.1.1.1 1033 99.99.99.10 1108 78.2.204.174 1257 78.2.8.181 file 2: test1 78.2.8.181 p6 test2 99.99.99.10 p9 test7 1.1.1.1 ...
1
vote
3answers
347 views

Script matching literal pattern over multiple lines?

I have a multi-line string in the variable $PAT. $PAT must be searched for within the file $FILE. If $PAT is in $FILE, it needs to print the file with $PAT removed. If $PAT is not found, then print ...
3
votes
5answers
172 views

grep device name and look for next value :

I have this output from a find command: abc,10.11.13.14,def,1.2.3.4,geh,6.7.54.23 where abc,def and geh are device names and could be of any length and others are IP address belong to devices. ...
7
votes
10answers
890 views

What's a good way to filter a text file to remove empty lines?

I have a .csv file (on a mac) that has a bunch of empty lines, e.g.: "1", "2", "lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum ...
4
votes
1answer
862 views

awk high precision arithmetic

I am looking for a way to tell awk to do high-precision arithmetic in a substitution operation. This involves, reading a field from a file and substituting it with a 1% increment on that value. ...
0
votes
1answer
46 views

how does this work in awk even without print?

bash-3.00# cat > b1.txt AAA,Apples,123 BBB,Bananas,124 CCC,Carrot,125 bash-3.00# cat > b2.txt Store1|AAA|123|11 Store2|BBB|124|23 Store3|CCC|125|57 Store4|DDD|126|38 bash-3.00# awk -F"[,|]" ...
1
vote
1answer
287 views

How do associative arrays work?

bash-3.00# cat iplogs.txt 180607 093423 123.12.23.122 133 180607 121234 125.25.45.221 153 190607 084849 202.178.23.4 44 190607 084859 164.78.22.64 12 200607 012312 202.188.3.2 13 ...
2
votes
1answer
320 views

Can i update my commands( like awk,sed) to the latest release in solaris?

bash-3.00# awk '{print NR}' f1.txt 1 2 3 4 but FNR does not print anything. awk '{print FNR}' f1.txt the above line does not gives me any output,seems that the awk that i am having in my ...
1
vote
2answers
324 views

Deleting specific lines and duplicates from a 11gb wordlist text file

I have an 11gb wordlist file which is already sorted as each word is on its own line. I need to remove duplicates and lines starting from 077. I guess I need to run sed and sort -u together but I ...
0
votes
1answer
94 views

Sort Column with matching string

I have tab-demlimted file, I want to sort them only for red_ball as follows input.txt id tagid name HH556 EN76 red_ball JH678 EN45 green_ball MH678 CV67 red_ball TY896 ...
1
vote
2answers
148 views

Missing float function in awk on RHEL 5.8

Why is float missing in awk on my RHEL 5.8? Was it replaced by some other function? On Solaris: echo "Foampile=123" | awk -F"=" '{ print float($2) "<->" $1 }' returns 123<->Foampile ...
2
votes
2answers
1k views

How can I use awk to extract URL's from a HTML file?

I have an HTML file with javascript and CSS in the source. Listed in the JS is a series of URLs' embedded with other meta-data. I want to use awk to extract the URLs (all enclosed in double quotes ...
2
votes
1answer
1k views

Diff, show modified line from right file only

I have file a and b and I would like to output lines of b that changed since it was cloned from a. Just the modified lines, no surrounding context, no diff offset marks. How can I do that using shell ...
1
vote
3answers
2k views

Print lines where first field has only four characters using regex in awk?

John Goldenrod:(916) 348-4278:250:100:175 Chet Main:(510) 548-5258:50:95:135 Tom Savage:(408) 926-3456:250:168:200 Elizabeth Stachelin:(916) 440-1763:175:75:300 output should contain the lines ...
2
votes
1answer
296 views

Replace semicolons to commas between the quotes only [duplicate]

Possible Duplicate: Remove comma between the quotes only I'm trying to use awk function to replace the semicolons between quotes to comma and it is 98% ok for me, because I want to keep the ...
1
vote
1answer
122 views

renaming diverse files

I store files named like this: word-word2-word3-word4.txt . The number of "words" varies from file to file. I want to replace certain of the dashes with pluses e.g word+word2-word3+word4.txt I want ...
1
vote
2answers
917 views

external variable in awk [duplicate]

Possible Duplicate: Use a script parameter in awk I have a script, in which a script snippet is x=3 awk '$2=$x{print $1}' infile the external variable is x, but it prompts an error in ...
8
votes
4answers
8k views

Remove line containing certain string and the following line

I use this cat foo.txt | sed '/bar/d' to remove lines containing the string 'bar' in the file. I would like however to remove those lines and the line directly after it. Preferably in sed, awk or ...
0
votes
2answers
443 views

put rows of numbers into a column with shell script

I have a file with many lines, like 1 jfkdajfd 1 2 3 5 2 fkldfjld 3 fdkfloaf 9 10 4 fldfldkf 5 fdskf;ak 12 1 4 I want to get all the numbers and put them in a column in a file, like 1 ...
2
votes
4answers
674 views

Replace all but a set of characters in a file with newline

how to delete all characters in file except numbers and "." , each word (numbers/dot) should be in new line in file see example2 the solution can be with sed or awk or ksh syntax remark - ...
0
votes
2answers
219 views

Easiest way to find/replace in a file using a list?

I have a file, foo.txt, and a regexp I want to find in that file. Each time I find the regexp, I want to take a line from another file, bar.txt, and substitute it in for the regexp match I found in ...
1
vote
1answer
938 views

awk - get input from both file and STDIN?

Is it possible to get input from both file and the terminal? I wish to ask the user something in the END portion of the awk script. That input should be typed in by the user and not read from the ...
2
votes
3answers
1k views

How to cat a file from awk?

END { file = "a.txt" system(cat file) } I wish to do something like that? (open a file whose name is in an awk variable). How is it done?
4
votes
5answers
2k views

Convert formatted dates to seconds since the epoch

I have a file: pablo tty8 Thu Nov 1 12:51:21 2012 still logged in (unknown tty8 Thu Nov 1 12:50:57 2012 - Thu Nov 1 12:51:21 2012 (00:00) pablo tty2 Thu Nov 1 12:50:39 2012 still logged in pablo ...
0
votes
3answers
71 views

Fixing header and print

I have header starting with '>' and I want fix the header by keeping first word and removing other shown as in output.txt and print it input.txt >AGAJ01065549.1 ...
0
votes
3answers
634 views

Split and print

I have tab-demlimted text file with 50,000lines. I want to split the first column and print as shown in output.txt Input.txt rt|371443144|mb|MN556661.1| 2200443 A rt|371443344|mb|MN556645.1| ...
5
votes
2answers
1k views

Replacing missing value blank space with zero

I have input.txt tab-delimited text file around 30K lines, I would like to check each row (s1..s30K lines) for missing value (i.e blank space) and fill the missing value with zero value.See out.txt ...