Parse ouput within an AWK Command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parse ouput within an AWK Command
# 1  
Old 02-17-2012
Parse ouput within an AWK Command

I have a script that I am writing to parse the output of information from a command.

Here is one of the lines of the output exported into the variable OUTPUT:

 
export OUTPUT=”name_of_system,0,5,9,55,ip_address,another_value,/PATH/OF/A/VALUE/I/NEED"

I can get the output I need with the following awk command:


echo $OUTPUT | awk -F, '{print $1"*****"$6"*****"$8}'

[root]# echo $OUTPUT | awk -F, '{print $1"*****"$6"*****"$8}'
name_of_system*****ip_address*****/PATH/OF/A/VALUE/I/NEED


However, I want to take the value in field 8 and awk out the last value in the path as in:



echo $OUTPUT | awk -F, '{print $8}' | awk -F/ '{print $7}'

[root]# echo $OUTPUT | awk -F, '{print $8}' | awk -F/ '{print $7}'
NEED


I know that I should be able to do it all within one line, but can not figure it out.

Last edited by jim mcnamara; 02-17-2012 at 08:48 PM.. Reason: The output did not look correct
# 2  
Old 02-17-2012
use basename command
Code:
result=$( basename `echo $OUTPUT | awk -F, '{print $8}'`  )

That way you no have to worry about which of the / fields is the last one
# 3  
Old 02-17-2012
As an alternative you may try this with sed too to fetch NEED:
Code:
result=`echo $OUTPUT | sed 's:.*/::'`

# 4  
Old 02-17-2012
Code:
$ echo $OUTPUT|awk -F, '{sub(/.*\//,"",$8);print $1"*****"$6"*****"$8}'
name_of_system*****ip_address*****NEED

# 5  
Old 02-18-2012
Try:
Code:
echo "${OUTPUT##*/}"

# 6  
Old 02-18-2012
These are great responses, will not get to try them till Monday. Any one have a good link to a awk tuturial to help me understand it better? I know there is a lot of power in it, but can not learn it well enough to harness it... Thanks for the replies.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to ouput not in file2 using awk?

Hi All, Seeking for your assistance on how to ouput the file which is not match in file 1 and file 2 using awk. I tried NR=FNR but it's not working, it will only show the match record. Ex. File1 abc def ghi File2 23a gd abc Output: abc (2 Replies)
Discussion started by: znesotomayor
2 Replies

2. Shell Programming and Scripting

Use of awk or sed to filter out the ouput

Hi, i am trying to get the system model with the help of awk : $ prtconf | awk '/^System Model/' System Model: IBM,8408-E8D but i want just the below outout that is command should chk for pattern <IBM,> and remove it from the final output : System Model:8408-E8D Can... (2 Replies)
Discussion started by: omkar.jadhav
2 Replies

3. Shell Programming and Scripting

Using awk to Parse File

Hi all, I have a file that contains a good hundred of these job definitions below: Job Name Last Start Last End ST Run Pri/Xit ________________________________________________________________ ____________________... (7 Replies)
Discussion started by: atticuss
7 Replies

4. Shell Programming and Scripting

Parse input -AWK

Input File Defined configuration: cfg: CLL_DCC_Fabric_A BTS00P21; BAU_AP00P01QC; BAU_LGSCNJP02; BAU_TS00P20; BAU_DSMSM14; BAU_HT00P02; BAU_DSMSM13; BAU_HT00P01; cfg: CX0014_list BAU_TS00P20; BAU_NYP_PRODIAD1_CJ;... (5 Replies)
Discussion started by: greycells
5 Replies

5. Shell Programming and Scripting

AWK Command parse a file based on string.

AWK Command parse a file based on string. I am trying to write a shell script to parse a file based on a string and move the content of the file to another file. Here is scenario. File content below Mime-Version: 1.0 Content-Type: multipart/mixed; ... (2 Replies)
Discussion started by: aakishore
2 Replies

6. Shell Programming and Scripting

A mistake in awk command I used to parse numbers

Hi I have a big file with a certain pattern (shown below) from which I need to parse out some digits in tabular format. The format of the file is: '-' indicates text which doesn't to be parsed # Output of huzzle for sequence file 1000.Clade1.html - - - -- -------... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

7. Shell Programming and Scripting

Parse file using awk and work in awk output

hi guys, i want to parse a file using public function, the file contain raw data in the below format i want to get the output like this to load it to Oracle DB MARWA1,BSS:26,1,3,0,0,0,0,0.00,22,22,22.00 MARWA2,BSS:26,1,3,0,0,0,0,0.00,22,22,22.00 this the file raw format: Number of... (6 Replies)
Discussion started by: dagigg
6 Replies

8. Shell Programming and Scripting

awk/sed Command: To Parse Stament between 2 numbers

Hi, I need an awk command that would parse the below expression Input Format 1 'Stmt1 ............................'2 'Stmt2 ............................'3 'Stmt3 ............................'4 'Stmt4 ............................'5 'Stmt5 ............................'6 'Stmt6... (1 Reply)
Discussion started by: rajan_san
1 Replies

9. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies

10. UNIX for Dummies Questions & Answers

parse string with awk

Hi Guys, I spend half a day getting this to work with no luck, perhaps you guys can help.. I have a string from a file looking like this: module::name=test::type=generic_data::exec=snmpget.......::desc=A Little Test::interval=300 what I would like to split it, so I get a value for each... (3 Replies)
Discussion started by: hyber
3 Replies
Login or Register to Ask a Question