awk - pattern-directed scanning and processing language

learn more… | top users | synonyms

2
votes
1answer
310 views

shell variable in awk is not being passed to all the lines but just for the very first line of input?

inputfile:is2.txt 10.39.5.41,A1,B1 10.39.5.41,A2,B2 10.39.5.41,A3,B3 10.39.5.41,A4,B4 10.39.5.41,A5,B5 10.39.5.41,A6,B6 script : #!/bin/bash second_column="OOOOOOO" # OOOOOOO will be added to ...
1
vote
2answers
415 views

reading from a file and changing its pattern into an array?

I have a CSV file containging entries like this : ipaddress,VLAN,VLANid 10.192.168.1,vlan-xyz,3 10.192.168.1,vlan-abc,8 10.192.168.1,vlan-mnp,11 10.192.163.24,vlan-llz,3 10.192.163.24,vlan-bbz,5 ...
1
vote
4answers
86 views

How to find what device a file is on (and use that in a script)?

I want to find out what device my file is on so that I can use it in a script. I can get this far: $ df . Filesystem 512-blocks Used Available Capacity Mounted on /dev/disk0s2 498438976 ...
1
vote
2answers
148 views

sed pattern matching with deletion over a line

I want to delete only some spaces(say 4) after the line$#*425 with space I am not able to complete it please suggest echo "line$#*425 with space " | sed 's/ /\1 \2/g' i am thinking of ...
1
vote
2answers
717 views

Print fields from file only if line starts with a specific word

I have the following file: … LINK=dummy 172.17.100 => 10.218.11 [PATH=/etc] FILE=hosts 172.17.100 => 10.218.11 [PATH=/etc] FILE=network 172.17.100 => 10.218.11 ...
1
vote
1answer
191 views

Regex to Cisco Interface

I would like to know if have some sed, grep or awk regex to parse Cisco interface section and exclude if interface is down (shutdown), like example below. Example: ! interface FastEthernet0/1 ip ...
1
vote
0answers
429 views

How to awk printf additional string with backslash

I have a csv that I want to add a preceding column to and a trailing column. The trailing column is a date (manual string right now). Every time I try to get that date, it ends up replacing some text ...
1
vote
1answer
2k views

How to calculate average requests per seconds using awk or sed on Apache logs

I am trying to calculate the average requests per seconds for a specific period of time of my Apache logs. I have been able to narrow the results down to the period I am interested in, as well as ...
3
votes
2answers
714 views

Split log file by time range

I have a log file and would like to cut it into copies of 15min. In the log file the lines start with: dd mmm yyyy hh:mm:ss,xxx e.g. 12 Feb 2013 16:05:02,xxx log text... and the file rotates ...
6
votes
4answers
13k views

Text between two tags

I wanna retrieve whatever is between these two tags – <tr> </tr> – from an html doc. Now I don't have any specific html requirements that would warrant for an html parser. I just plain ...
3
votes
2answers
386 views

AWK for data smoothing

I need some help to smooth some data with awk olny of column 4 and next. This is a data example: Date;time;Time_ms;A;B;C;D 23.11.2012;15:03:00;41236627696;1;2;2;3 ...
4
votes
2answers
3k views

System calls, AWK, and Bringing in external inputs

awk '{ TEMPVAR="/usr/bin"; printf("%s", system("ls $TEMPVAR")); }' empty In this example I'm trying to bring in the variable TEMPVAR into the system call. How would I do this? What I'm aiming to ...
3
votes
2answers
1k views

AWK : Converting Row Formated Data into Columnar

I have a dataset as such: Name: Jim Bean Vice: Dice ID: AFDSDFDSFDSFASFA LoginTime: 12343314 Name: Bob Dylon Vice: Trumpets ID: AFD232SFDSFASFA LoginTime: 12343314 ...
5
votes
2answers
321 views

what is the meaning of 1 at the end of awk script

I was reading this awk script awk -F"=" '{OFS="=";gsub(",",";",$2)}1' I want to know what is the function of 1 at the end of it
2
votes
1answer
3k views

How can I use awk to (sometimes) remove the first character of a column?

I run a command and pipe it through awk as below : mycommand | awk '{print $1,tolower($3),$4} This gives me the following output: fred.o: t .abcdefg fred.o: u .rstuvwxy fred.o: t .defghi ...
0
votes
2answers
77 views

Co Record Verification

I have a task requiring some awk to verify a few records quickly. Let' say: A1,A2 B1,B2 C1,C2 C2,C1 A1,C1 A1,B1 B1,A1 Which would be the best way to check for reciprocity only between the A# the ...
2
votes
1answer
263 views

Parse csv using awk [duplicate]

Possible Duplicate: Is there a robust command line tool for processing csv files? I am trying to parse the second line in a file (which contains commas within double quotes) "100 Watt ...
3
votes
2answers
448 views

sort a file based on length of the column/row

I need to sort a file based on the number of chars in the first column. I have no idea on how to go about this. (On Linux, so sed/awk/sort is available). An example: .abs is bla bla 12 .abc is bla ...
2
votes
1answer
550 views

Conky - string formatting

I have conky the record: ${color lightblue} Down: ${downspeed wlan0} Up: ${upspeed wlan0} Conky prints link speed, but the text moves: Down: OB Up: OB Down: 60B Up: 60B Down: 148B Up: 148B ...
3
votes
3answers
2k views

How can awk cut certain fields and add to the end of each line?

I would like to convert a list containing bunch of svn URLs of issues: cat list.txt //svn.server.address/repos/project/module1/branches/issue-001-name1 ...
1
vote
2answers
1k views

Parsing string by awk and get only elements without pipes or semi colons

I would like get this string line AUGUSTYN|Stanisław|3589238 without | and : I tried something like that: cat baza|grep "AUGUSTYN" -n|awk -F '|' '{print $1,$2,$3,$4}'` (baza is my file with ...
3
votes
1answer
218 views

No output from inotifywait | awk

I'm attempting to use part of a one-liner found here: Script to monitor folder for new files? When I try the following procedure I get no output whatsoever and I cannot figure out why. In terminal ...
1
vote
2answers
2k views

Help inserting a new line of text after matching a line of text (sed)?

I need to insert a hidden HTML input tag into any form tag within a bunch of HTML files. I assume this is possible with sed, but need help forming the command. My idea is to search for any instance ...
2
votes
2answers
196 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
534 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
2k 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
606 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 ...
4
votes
5answers
9k 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
2k 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
612 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
2k 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 ...
4
votes
1answer
285 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
198 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
238 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
131 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
137 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* ...
2
votes
5answers
557 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
3k 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
2k 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
492 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
2k 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
720 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
1k 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
454 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
323 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
118 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
1k 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 ...
3
votes
3answers
553 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
193 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
2k 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 ...