awk - pattern-directed scanning and processing language
0
votes
2answers
16 views
dynamically add the number in the coloumn if exists
Need to count Nodes_Util for each Queue, in the below example queue is having only one line but it varies and it could be nothing sometimes and it applies to all queues
dynamically add the number in ...
1
vote
2answers
18 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
58 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
58 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
16 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
50 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
74 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
22 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
47 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
46 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
58 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 '.
-2
votes
0answers
61 views
Sort and remove dupes using awk command in bash [closed]
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
40 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
194 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
104 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
259 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
80 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
32 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
119 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
51 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
57 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
142 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
76 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
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
38 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
48 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
155 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
58 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
46 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 ...