awk - pattern-directed scanning and processing language

learn more… | top users | synonyms

-1
votes
3answers
29 views

Filtering multi-lines from a log

Should this question be moved to stackoverflow instead? I often need to read log files generated by java applications using log4j. Usually, a logged message (let's call it a log entry) spans over ...
2
votes
2answers
45 views

Need to obtain Awk output in specific sequence

Data in file: 1234567-5678907 3456789-1234563 3456789-1234567 . . . . n Now I want the output in the below format: 1234567-5678907,3456789-1234563,3456789-1234563....n I have used below command ...
1
vote
1answer
34 views

Can't use find -print in AWK

I'm trying to put together a command to find SUID System Executables, which are not the default ones in RHEL. To do this, I'm pulling a list of the local File System (df --local -P), piping it over ...
0
votes
0answers
46 views

How to parse an awk variable

I'm trying to pull some information out of a log file, looking back over a specific period of time (e.g. the past hour). I've found the following awk construct that works, capturing the data as a ...
0
votes
3answers
47 views

Due to spaces between one Word Awk changed output

Due to spaces between one Word Awk changed output e.g : "Local Address" awk consider local and address Separately # netstat -antulp | awk 'NR>1' Proto Recv-Q Send-Q Local Address ...
-5
votes
2answers
57 views

How to average a column in a text file without using ' character? [on hold]

I need to do it without using the ' character. I could do it like this: awk '{sum+=$5} END { print "Average = ",sum/NR}' except this contains a '.
-2
votes
0answers
57 views

Sort and remove dupes using awk command in bash [on hold]

Hi Another situation i have is as explaned below: EX: I/P file a|a1|a2|a3|a4|a5|...|a29|#2342 a|a1|a2|a3|a4|a15|...|a29|#2349 a|a1|a2|a3|a4|a5|...|a29|#2344 a|a1|a2|a3|a4|a5|...|a29|#2344 ...
0
votes
3answers
37 views

modify file using awk or sed

I have a text file contains ldap data in the give below format, our default structure says every user must have its own respective "home directory" but in given below i found many users have the same ...
-1
votes
0answers
36 views

Filter the diffrent specific string with awk

I have copied all the JOBS into a file "job_notrun_2015" which conatins the JOB name and their status like IO /SU (means inactive or success). Now i need to fileter First "job_type" where its "BOX" ...
2
votes
1answer
30 views

Remove Quotes (double or single) with Awk

I want to remove quotes(double quotes) appearing in the awk output, how it can be achieved # systool -c fc_host -v | awk '/Class Device =/{host=$4}/port_state/{print host,$3}' (This is my awk ...
2
votes
3answers
192 views

How to find a specific 'string' and print out the whole line?

I have a file named myfile.csv containing the following: abc:123:myname:1231 def:423324:arbitrary:value:string StackExchange:Unix:Linux From the terminal I run ./myscript.sh def The contents of ...
1
vote
2answers
56 views

Print line have special format and amount of comma

This is my sample : 6751176513,ahggasda,3453453,hgdahgsd,hgfhgfhg,, ,, ajhgdha | sajhsgdahj|sdahgdhjaghjsd 6751176513,ahggasda,gdfgdf,2015-10-20 05:15:25,sdfsd,, I need to print the lines that ...
1
vote
4answers
102 views

matching and merging lines with awk & printing with Solaris

I want to merge the matching pattern with awk on a Solaris system. $ luxadm probe No Network Array enclosures found in /dev/es Found Fibre Channel device(s): Node WWN:2000000c50f1c8da Device ...
0
votes
1answer
58 views

Is there a way to use sed or awk to filter data inside a zipped file? [duplicate]

Is there a way to use sed or awk to filter data inside a zipped file? When I run a sed or awk command and send to stdout the file created is 0 bytes.
1
vote
2answers
44 views

Insert line after matching line in sshd inside pam.d

I want to insert a line after matching line in sshd file which is present inside pam.d directory. For e.g. it should search for this line account required pam_nologin.so and it should ...
2
votes
3answers
169 views

AWK & Bash: Checking that a User's Home is Owned by the User

I'm trying to cycle through /etc/passwd with a single-line command in order to find those users who have a home directory which is not owned by the user, but I'm VERY new to bash programming, and I ...
1
vote
1answer
35 views

Displaying “No Results” When AWK Command has no output

I have the following code, thank-you to the people who helped me here awk -F: '{if(system( "[ -d " $6 " ]") == 1) {print "The directory " $6 " does not exist for user " $1 }}' /etc/passwd However, ...
8
votes
4answers
254 views

How do you check if a file exists within awk? [-d 'filename'] failing

I'm trying to generate a list of users who have a home directory set which does not exist. It seems I should be able to do this with awk, but something is wrong with my syntax. It keeps telling me ...
0
votes
1answer
46 views

How to accumulate data for the previous x number of days

Q: For the argument of the question, say today is 26/03/15. How can I 'accumulate' data for the last 5 days. But these dates are just an example. Ideally I would like to be able to accumulate data ...
1
vote
0answers
26 views

Unix : Merge the contents of two files using common key present in the files [duplicate]

Objective : Merge the contents of two files using common key present in the files file1.txt ========= key1 11 key2 12 key3 13 file2.txt ========= key2 22 key3 23 key4 24 key5 25 ...
2
votes
4answers
75 views

Why isn't this awk command doing a full outer join?

Objective: Merge the contents of two files using common key present in the files file1.txt ========= key1 11 key2 12 key3 13 file2.txt ========= key2 22 key3 23 key4 24 key5 ...
0
votes
2answers
30 views

How to scrape multiple IP's and add in a script as a variable?

I am trying to add in my script an awk statement or a: if; else; then if eth0:4 is a match then put in eth0:4 IP How would you get the IP in your script as a variable if you have multiple IP's ...
4
votes
3answers
118 views

Remove duplicate lines while keeping the order of the lines

[root@server]# awk '!seen[$0]++' out.txt > cleaned awk: (FILENAME=out.txt FNR=8547098) fatal error: internal error Aborted [root@server]# The ""server"" has: 8 GByte RAM + 16 GByte SWAP, x>300 ...
0
votes
2answers
52 views

Awk one-liner to print column of SQL table?

Suppose I have table like: This is first line name minimum maximum config_value ----------------------------------- ----------- ----------- ------------ some ...
1
vote
1answer
48 views

Output different lines when comparing two files

I have two text files with the same number of newline terminated strings. The lines in the two files correspond to each other. The lines in each file individually might be repeated. I would like to ...
3
votes
3answers
517 views

awk floating point arithmetic - surprising result

I've been trying to get awk to do some trivial arithmetic, which involves carrying some values from one line to the next. Here is a minimal example pair, for comparison. The first example is expected ...
0
votes
4answers
56 views

How to remove line based on Delimeter in perl / Shell?

Can anyone help to remove the line in file based on delimeter(Comma), Incase if line contain less number of columns or Bad records , Need to delete those. Input File: a,b,c,d a,b,d,f c,d a,v,b,h ...
2
votes
4answers
124 views

How do I extract the first integer from text string in a column of a tab-delimited file?

I work in Medical Genetics and often have delimited text files where in one column (ex. column 5) there is a text string with a "mutation" in our jargon: c.2458C>T or c.45_46delAA or ...
0
votes
0answers
40 views

awk & grep to search for all strings in file1 on file2 where strings can have pipe [duplicate]

Please ignore - this post is a duplicate of this one. I have file-1 which has list of transaction id . File -1 ...
1
vote
1answer
73 views

string search using awk

I have file-1 which has list of transaction id . File -1 201503301616|9b8791b3-f860-409f-aad0-24debf834c1b|10.233.18.29.677220869928387637969 ...
0
votes
2answers
55 views

Find and replace values with counters [closed]

Sorry my earlier question was bit confusing... I have a file that has values like: location 100 SlotNumber ..some lines inbetween location 150 SlotNumber ..some lines inbetween location 160 ...
0
votes
3answers
78 views

awk to remove string from a variable

HP-UX *** B.11.31 U ia64 ***unlimited-user license I want to move a file in the current directory called abc.txt to a directory called ./begperl. While I do so I want the moved version of the file to ...
3
votes
1answer
37 views

Extract first word after pattern that includes `[…]`

I have an issue when I try to extract the first word after grep matches my pattern . Let me show you an example : cat test.txt [profile dev] xxx xxx [profile prod] xxx xxx now I want to extract ...
0
votes
2answers
32 views

Select lines and format

Is there a way to format the following output so that only lines 1 and the respective lines that state the "rule" name print out? Depending on the configuation, the "rule" line could vary. It could be ...
0
votes
2answers
39 views

list the “middle” part of an input in the end of the output in awk

This is regarding a hostfile. INPUT: 1.2.3.4 foooo00001 foo001 # AIX bar0003 NOSLS NOSLS NOCOMMENT 2.3.4.1 foooo00002 foo002 fooo0002 # Linux bar0003 NOSLS NOSLS NOCOMMENT OUTPUT: echo "$INPUT" ...
1
vote
2answers
44 views

Script to hang up Asterisk channels

I am trying to create a script for Asterisk. We use a lot of channspy. Sometimes the channspy stays opened and didn't hangup even if the softphone is hangup (I don't understand why). So I thought of ...
4
votes
3answers
154 views

Get last part of string after hyphen

Is there a simple command line to extract the last part of a string separated by hyphens? E.g., I want to extract 123 from foo-bar-123.
2
votes
1answer
51 views

How to select lines and reformat command output?

Is there a way to format the following output so that only lines 1 and 4 print out? It would be best if the first line and fourth line could come out on the same line like this: sw pool test(no ...
1
vote
5answers
57 views

keep out line break

I have some files with this structure: 2015-03-25 17:08:17 sysUpTimeInstance 93474;^M 1.ValueforState=2500 I want to replace the line break, and leave the third line with the second line, I mean, ...
-2
votes
1answer
41 views

how to print new word after two lines using awk

I need to insert a blank line after two lines in a file that i did with cat rat hat pot NOT lot big big big sit sit sit awk '{print};(NR%2==0){print ""}' cat rat hat pot NOT ...
1
vote
1answer
48 views

sort and uniq in awk

I know there are "sort" and "uniq" out there, however, today's question is about how to utilise AWK to do that kind of a job. Say if I have a list of anything really (ips, names, or numbers) and I ...
1
vote
1answer
35 views

awk script to rearrange similar rows

I want rearrange about 5 million rows (with 300 columns) into groups. Data looks like the following: where there were various experiments (column 2) conducted at different locations (column headers ...
0
votes
4answers
39 views

AWK print regex pattern

I am trying to print a regex pattern for the following piece of mail log. In particular I am trying to get the ID between the square brackets (see the second line for reference). Mar 29 03:48:13 ...
0
votes
3answers
39 views

How to display only the last line of a listing ?

Supposed I make a listing and sort the files by its temporal attribute: ls -ltr -rwxrwxrwx 1 bla bla 4096 Feb 01 20:10 foo1 -rwxrwxrwx 1 bla bla 4096 Feb 01 20:12 foo2 . . . -rwxrwxrwx 1 bla bla ...
0
votes
2answers
63 views

Print awk's current new line character

How can I find what new line character is in my file when using awk? I know the default is \n but this is what manual says. I want to see it with my own eyes. I have just started learning awk and ...
1
vote
1answer
46 views

Write text on last line of document [duplicate]

If I have this document aaa bbb ccc And I want to add " ddd" on the last line. My document should look like this: aaa bbb ccc ddd How can I do this? If I prefer awk or sed but ...
2
votes
2answers
88 views

How to print from a given range of ip addresses every class-c with the last octect replaced by an asterisk

example: I have a range from 10.0.100.0 to 10.0.224.0 and I want the output like this: 10.0.100.* 10.0.101.* 10.0.102.* and so on
-1
votes
1answer
30 views

AWK and Bash Scripting [duplicate]

How to use a value of a variable in awk? Something like this: filename = "test.txt" ls -l | awk '{ if ($9 == filename) print("File exists")}' I can't use $ in awk to access the value of ...
5
votes
1answer
56 views

How to use ^#$ as record separator in awk?

How do you tell awk to use a # character by itself in a line as record separator? The problem is you can't say RS="^#$" because ^ matches the beginning of the file, not the beginning of a line, and ...
0
votes
2answers
97 views

How to delete specific lines within a certain area?

I want to delete some specific lines in the YAML front matter: --- Author: aaaa Title: bbbb Time: cccc Place: dddd ... Lets say I wanted to delete only the lines in the front matter that contained ...