awk - pattern-directed scanning and processing language

learn more… | top users | synonyms

2
votes
4answers
74 views

Change text in tag, but only tag is contained within a certain XML block

Using Git Bash, I'm trying to conditionally replace what's in the yrot tag in hundreds of files, but only if it belongs with a part name tag that pertains to wheel. // YES, change <part ...
0
votes
2answers
41 views

How to find and replace only a particular word (which is at the end of the file) using shell command?

File1: Dms 01.01.2015 feeder1 6kv close at 04:30 Updated Dms 01.01.2015 feeder1 6kv open at 06:20 Updated Dms 04.02.2015 feeder10 6kv close at 17:23 Updated Dms 04.02.2015 feeder12 6kv ...
1
vote
1answer
54 views

How to write data one by one from tmp files to the final output file using for loop?

I have two tmp files named tmp1 and tmp2 which contains some lines. tmp1 file, 1c\ datafile no. 23 2c\ datafile is ok tmp2 file, 3c\ datafile no. 24 4c\ datafile is ok I have a ...
4
votes
2answers
164 views

how to extract parts of file into separate files in linux using awk or grep or sed commands

I have text file as shown below: Input file1.txt ....................... cha21 1 3 5 nar cha21 2 3 6 piy cha23 2 3 5 ram cha23 3 ...
2
votes
5answers
115 views

Adjust gap between 2 columns to make them look straight

file1.txt: hi wonderful amazing sorry superman superhumanwith loss file2.txt : 1 2 3 4 5 6 7 When i try to combine using paste -d" " file1.txt file2.txt > actualout.txt actualout.txt : hi 1 ...
1
vote
2answers
26 views

Addition of values

foo.txt: Lillypaul_sg 204803 204803 204803 Ammy_sg 3 ramaswamy_sg 3 33 tommy_sg 3 3 137374 100 Desired Out.txt : Lillypaul_sg 614409 Ammy_sg 3 ramaswamy_sg 36 tommy_sg 137480 The output is a sum ...
2
votes
3answers
31 views

Truncating the precision of a date

I'm working with a bash script which polls build progress from several different systems. If a build is complete, it stats a log file to find out the last time it was edited, then feeds that time into ...
0
votes
1answer
35 views

How to remove certain number of lines every time particular string is found in file

I want to remove 1 previous line and 10 following lines every time a string was found in the file. foo.txt: } Name: john Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Line 11 Line 12 ...
1
vote
2answers
41 views

How to print few lines from middle of a file using unix shell commands? [closed]

My file containing the following lines, $BQ { VOL @home } database daba relation tcdeatid opendb clear .lruno := 72 <-- (This line lruno. := 72 has 10 times ...
5
votes
8answers
450 views

How do I delete the first n lines and last line of a file using shell commands?

I have a file named Element_query containing the result of a query : SQL> select count (*) from element; [Output of the query which I want to keep in my file] SQL> spool off; I want to ...
1
vote
3answers
59 views

Sed Replace at a specific group of positions

I have a sample input file as below: Apple Orange Gold Silver Spoon Apple Orange Gold Apple Apple Orange Apple Orange Mango Gold ...
3
votes
2answers
71 views

shell script to extract between characters

I would like to extract a user name from the file between the keywords "/" and "NET" like below. How can I do so with programs like awk, sed or cut. from: audit: command=true ...
0
votes
2answers
47 views

Count frequency of specific numbers in a text file of scientific notations

Background I have a text file, named blood_conc.txt as shown: 0, 0, 0, 0, 0, 0, 0, 1.32006590271e-05, 1.990014992001e-05, 1.504668143682e-05, 2.176900659261e-06, 7.673488970859e-06, ...
3
votes
4answers
205 views

Extract paragraph separated with *** using AWK

I have a file like below: blablabla blablabla *** thingsIwantToRead1 thingsIwantToRead2 thingsIwantToRead3 blablabla blablabla I want to extract the paragraph with thingsIwantToRead. When I had to ...
-2
votes
4answers
56 views

How to print last few contents in a line?

I have a file that has lines shown below, ta=/*92/*39/*1/*649/*12 ta=/*92/*12/*4/*342/*90 ta=/*92/*33/*9/*455/*3 ta=/*92/*12/*3/*649/*25 ta=/*92/*99/*7/*649/*7 and so on. I want a file that will ...
2
votes
2answers
73 views

Check if conditional with awk for matches in logfile

I want to check the auth.log file for accepted sshd connections and execute an action if any are found. Here is my code: tail -f /var/log/auth.log | awk '{ if($0 ~ /sshd/ && $0 ~ /Accepted/) ...
0
votes
1answer
31 views

How to integrate awk parameters in awk range pattern

I need to get something like this #Batch Job - AB1234 texts texts texts texts texts #-------- I used awk '/#Batch Job.*AB1234/,/#--.*/' filename and i went well. But then when I tried to ...
4
votes
2answers
41 views

How to preserve mixed linefeed formats in gawk?

I have an input file which contains both Unix (LF) and Windows (CR/LF) style newlines. (Specifically, it's XML from a Linux system, but it contains some raw HTTP headers, and HTTP prefers CRLF for ...
3
votes
3answers
55 views

Output to stdout works, fails when redirected to a file or a fifo

I have a Wifi antenna and I want to optimise it's position. For that propose I'd like to visualise the current latency in real time. I wrote a one-line script to output the ping latency: lat.sh: ...
5
votes
3answers
145 views

Escape sequences passed as args to gawk not interpreted

I want to be able to pass an argument on the command line to gawk that is evaluated for escape sequences. The issue: $ gawk 'BEGIN { print ARGV[1]; }' '\t' \t Instead, I would like to get an ...
1
vote
1answer
35 views

Insert variable in specific place using sed

Please help me i'm trying to insert variable in a file with sed but has not yet successfully(( I have variable $time and i want insert it in index.html file in specific string(line number 53): the ...
4
votes
3answers
79 views

How to insert multiple blank lines after every line

I want to insert 5 blank lines after every line in my input file. foo.txt: line 1 line 2 line 3 out.txt: line 1 line 2 line 3 ... Solaris 5.10, nawk or sed.
0
votes
1answer
49 views

Why doesn't this simple piping with awk work? [duplicate]

I'm trying to follow this answer but I can't make it work. I simplified it down as much as I could to try work out what's going on (just running this at the terminal for now): rsync --progress -iav ...
0
votes
3answers
47 views

Extract value from one file and insert it into another file replacing some other value

I have two files, whose line numbers are not same. But in file1 I want to replace lines taking reference from file2 using sed command. In file1: tid.infno := 72 tid.setnr := 120 (This number 120 is ...
2
votes
4answers
100 views

Using Grep -o or Sed/Awk to Grab Snippet from Middle of String

I am watching log traffic and see regular abuse of the various image search engines, Bing particularly. Example URL: ...
2
votes
6answers
160 views

grep with continuation lines

How can I grep/awk/sed a file looking for some pattern, and print the entire line (including continuation lines if the matched line ends with \? File foo.txt contains: something whatever thisXXX ...
0
votes
3answers
54 views

How to sort/reformat text information in a file?

I have a file (called customers) with information that needs to be sorted; example: qweasd,asdqwd@asd.org,256.62394383 qweasdczasd,asdghjghqwd@assssd.org,256.62394383 ...
2
votes
3answers
51 views

Delete lines between 2 strings in Solaris

I want to delete all the line between two patterns using basic awk or sed. foo.txt : ---------------------------------------------------------------------- Cap in MB line 2 line 3 line 4 line 5 ...
-3
votes
1answer
66 views

AWK sum every two rows

I want to sum two rows until end of file: 1 2 3 4 0 1 2 3 0 4 5 6 2 3 5 6 Output should be 1 3 5 7 2 7 10 12 I have tried the following, but it only works for the 1st row awk ...
0
votes
2answers
36 views

Issue on awk input parameter in ksh

I am running this script: INPUTNAME=ABC.XYZ FILENAME="Sample.xml" awk -v inputName=$INPUTNAME ' /<machine.*name=/ { f=1 ; m=0 ; res="" } f { res = res $0 ORS } f && ...
0
votes
1answer
40 views

How to implement awk range pattern in fetching an xml block when the input parameter is in the middle of the block

I am trying to fetch an xml block like this: <machine name="sample1" min="1" max="10" idleTime="300" backend="ABC,XYZ"> <handler className="com.abc.xyz.qwerty.foo.FooBar" ...
2
votes
1answer
45 views

How to output a comparison of values in separate files

With the following two files available with build names and version numbers available: server.txt Build2 200 Build3 100 Build1 400 Build7 200 local.txt Build1 300 Build2 200 Build3 100 In my ...
4
votes
6answers
346 views

sed command to swap characters

My input file layout is: mm/dd/yyyy,hh:mm,other fields I need to format it as: yyyy-mm-dd hh:mm:00,other fields sample input: 01/02/1998,09:30,0.4571,0.4613,0.4529,0.4592,6042175 ...
2
votes
2answers
136 views

Awk: match exact string in line

I have this file a deiauk Biking US 200 G b kespaul 202 A c deiauk NY 222 5 Z And I want to match the exact string 200 using awk. So my result should be a deiauk Biking US 200 G Here's my code ...
2
votes
1answer
31 views

How is the order for which keys are stored and reteived determined in awk?

I am just starting to learn awk and was familiarizing myself with associative arrays only to discover that the order in which the keys were retrieved (or stored) didn't make a whole lot of sense. As ...
1
vote
3answers
131 views

Using AWK to convert numbers to 0 or 1

This might be a simple question but I can't figure it out for the life of me. I have a file called keyout.dat which looks like this: Title 1 Variable -999 -999 0.234 0.123 -999 -999 0.555 The file ...
1
vote
2answers
53 views

Awk: compare two files

I have a file1.txt USA Joe 123.123.123 Russia Marry 458.786.892 Canada Greg 151.844.165 Latvia Grace 125.895.688 and file2.txt 1 123.123.123 2 151.844.165 3 465.879.515 and I want to create a ...
3
votes
6answers
141 views

Extracting lines based on conditions

Each line in a comma-separated file has 5 fields. a,b,c,d,e f,g,c,i, j,k,c,m,n o,p,c,r,s t,u,c,w, x,y,z,aa,bb How can I extract the lines which have c in the 3rd field and their 5th field is NOT ...
2
votes
3answers
88 views

determining column number using string in awk

Suppose I have a pipe separated file like: |Sr|Fruits|Colors| |1 |apple |red| |2 |orange |orange |3 |grapes |purple| Here it is evident using awk that, $2 is Fruits and $3 is the colors column. ...
0
votes
2answers
24 views

get specific variable using awk

I have this file.txt kespaul pts/14 2001:778:200:180 Fri May 29 11:33 - 16:40 (00:07) kespaul sshd 2001:778:200:180 Fri May 29 16:33 - 16:40 (00:07) algvai pts/2 ...
1
vote
1answer
39 views

finding lines in a file matching patterns defined in another file

I have two files file1.txt kepaul jack mike david and file2.txt 1 london smith 12564 2 miami jack 51616 3 la mike 165156 4 london kepaul 54654 5 miami grag 46546 and I need to print to a new ...
0
votes
3answers
87 views

Find all words beginning with Q

How do I search a text file and list all the words begining with Q? The file I am searching is Python source code. The closest I have found to a soulution is this question but that is not what I ...
1
vote
2answers
46 views

Specify String Lenth in Awk Pattern Search

I'm not sure what I'm doing wrong. Given a test.log of: 123.123.123.123 321.321.321.321 GET /test1234/asdfasdfpioasdfjkhweris,9 123.123.123.123 321.321.321.321 GET ...
0
votes
0answers
34 views

awk search for string containing forward slash in variable [duplicate]

I'm searching for a string in a massive XML file. Snip: <sv:node sv:name="notfound"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> ...
0
votes
3answers
52 views

How do I pass a series of patterns into awk from a shell script?

I've got a series of patterns stored in foo.txt and I want to iterate over those patterns and see which match lines in file bar.txt. while read PWW do cat user/dump/bar.txt | awk '/${PWW}/{print ...
2
votes
2answers
48 views

How to exclude lines that don't include a string from the output of an awk script?

Completely new to scripting in general, and have been working on a script to go through our logs which contain entries for a variety of different things. What I'm interested in, is the entries that ...
3
votes
2answers
126 views

how to print field between the double quote

I have the following file conf.txt: perl /home/site/gen.pl "GG - W C1 Test - sai1" "15072" && ssh 13.4.93.103 perl /home/site/gen.pl "GG - W C1 Test - sai2" "15072" && ssh ...
15
votes
10answers
2k views

How can I quickly sum all numbers in a file?

Each line contains text and numbers in one column. I need to calculate the sum of the numbers in each row. How can I do that? Thx example.log contains: time=31sec time=192sec time=18sec time=543sec ...
2
votes
2answers
55 views

Add a number in a huge ASCII file

Background: (1) Here is a screen capture of a part of my ascii file (over 600Mb): (1.1) Here is a part of the code: 0, 0, 0, 0, 0, 0, 0, 0, 3.043678e-05, 3.661498e-05, 2.070347e-05, ...
0
votes
1answer
37 views

Move a range of words to the end of the string

I have the following string: "5 S comment=whatever Unspecific text fruit=apple animal=mouse sky=blue" I need to move to end of the string, all that begin with comment to the word text. The start ...