awk - pattern-directed scanning and processing language

learn more… | top users | synonyms

1
vote
1answer
53 views

Formatting grep output with awk. Simple case and background case

I'm struggling with this problem. I have this line: mplayer *.* 2>/dev/null | grep Playing which just launchs mplayer and only the line matching Playing filename is printed on screen. This works ...
0
votes
1answer
24 views

Multiple input files and output files in awk

I have a folder full of text files named 000.txt to 181.txt. How can I process all of them with the same awk script (program.awk) and send them to their respective output files (output000.txt - ...
0
votes
1answer
40 views

Search and replacing strings in a numerical data file

I have a data file I need to edit it is in the form: ...
0
votes
0answers
41 views

Shell intervals using awk

I have a file a 10:10 10:30 b 12:15 13:15 c 16:54 17:54 and I need to enter interval for example 10:15 so my output should be a 10:10 10:30 How I need to do that using awk?
1
vote
2answers
30 views

Using sed to replace javascript code in multiple files

I need to replace an old google analytics code with the new universal tracking code in lots of static html files. The old code looks like this: _uacct = "UA-XXXXXX-X"; urchinTracker(); The new code ...
0
votes
2answers
30 views

awk cut from specific word in string

I have those strings gcc-4.8.3-1.aix7.1.ppc.rpm gcc-c++-4.8.3-1.aix7.1.ppc.rpm gcc-cpp-4.8.3-1.aix7.1.ppc.rpm gcc-gfortran-4.8.3-1.aix7.1.ppc.rpm libgcc-4.8.3-1.aix7.1.ppc.rpm I want to cut ...
0
votes
1answer
37 views

Add the number in the column if exists

I need to count Nodes_Util for each Queue. In the example below, queue1 has only one line, but it varies and it could be nothing sometimes and it applies to all queues. I want to dynamically add the ...
1
vote
2answers
33 views

Skip the first 6 lines/rows in a text file with awk

How can I skip the first 6 lines/rows in a text file (input.txt) and process the rest with awk? The format of my awk script (program.awk) is: BEGIN { } { process here } END { } My text file ...
1
vote
6answers
66 views

Count the number of 0 and 1 in a file [duplicate]

I have a file (see below), and I would like to count the number of 1's and of 0's: 1 1 1 0 0 1 1 0 0 0 ... I tried to use awk but it doesn't work, for example, to count the number of 1's: awk -F ...
1
vote
2answers
62 views

How to strip time stamps from a file?

I have log which contains lines of data: Mon Apr 20 03:15:18 EDT 2015: my|data|data|data I am trying to write a script which would extract just the data from the log, stripping the leading time ...
1
vote
1answer
17 views

Unable to replace variable in shell script using awk

I have been struggling to replace every occurence of "<KEY>" in a file with ${encryptedkeyValue} I wrote this line but it is not doing ...
0
votes
4answers
40 views

Getting an error when running awk from a script

I have a file some.txt -rwxrw-r-- 1 ivamshky ivamshky 152 Apr 2 00:42 12.sh~ -rw-rw-r-- 1 ivamshky ivamshky 58 Apr 6 19:03 a.c -rw-rw-r-- 1 ivamshky ivamshky 98 Apr 1 20:27 all.sh ...
1
vote
2answers
51 views

Format Column Width with Printf

I have searched online for 10 hours now and tried various codes, but still need help. I am attempting to merge three files using 'paste' and 'awk'. However, the columns are not adjusting to the ...
3
votes
3answers
76 views

Match lines of a file with headers in other to obtain entire para

I want help with scripting to work with two files, wherein file 1 lists amino acids which are in specific order (one below the other and also might repeat) and the second file 2 constitutes the ...
1
vote
0answers
23 views

How to use awk-it in Emacs?

I'm a pretty new Emacs user and I want to call awk from Emacs. After googling around I found awk-it at http://www.emacswiki.org/emacs/AWK_It. However I still can't understand how to use it after I ...
1
vote
1answer
49 views

awk ifs and variables - cannot pass a variable from one line towards subsequent lines

First of all I'm new to awk so please excuse if it's something simple. I'm trying to generate a file that contains paths. I'm using for this an ls -LT listing as well as an awk script: This is an ...
0
votes
3answers
47 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
57 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
40 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
1answer
61 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
2answers
48 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
59 views

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

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 '.
0
votes
3answers
41 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
195 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
109 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
60 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
45 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
172 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
36 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
261 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
27 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
82 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
33 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
123 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
54 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
52 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
522 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
59 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
144 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
79 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
56 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
79 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
41 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
40 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" ...