extract line


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users extract line
# 8  
Old 06-15-2009
Data awk on Mac OS seems to be strange

Quote:
Originally Posted by ahmad.diab
it should work , what is the type of your work station ?... if you have gawk use it.
use the below after some changes:-

Code:
gawk -v RS='!\n'  -v ORS='' '($0 ~ /shutdown/) {print $1,$2," is down" }' inputfile

I use Mac OS X to create my script and then I put them on a FreeBSD. If I use your script on my FBSD it works, on my Mac OS no for the second conf file type... Strange! (and no I haven't gawk on my Mac)


It's the same for this:

Code:
awk '/interface/{f=$0} f && /shutdown/{print f $0; f=0}'  file


On my FBSD it works perfectly, but if use the config file I show you in my last message it display me this:

Code:
shutdown FastEthernet0/0
shutdown FastEthernet1/0

I'm sad about this, should I stop create my script under my Mac? Smilie

Anyway thanks for your help guys!
# 9  
Old 06-15-2009
Code:
try to find  all of the full paths of awk on your MAC system and put the full path of awk in the below code

/full/path/of/awk -v RS='!\n'  -v ORS='' '($0 ~ /shutdown/) {print $1,$2," is down" }' inputfile

to find the awk full paths use the below:-

find / -name "awk" -print 2>/dev/null

BR

# 10  
Old 06-15-2009
Just for information the path is /usr/bin/awk
But it change nothing, it still not work if I use the second conf file.

Thanks again for your help Smilie
# 11  
Old 06-15-2009
Quote:
Originally Posted by sylvainkalache
Just for information the path is /usr/bin/awk
But it change nothing, it still not work if I use the second conf file.

Thanks again for your help Smilie
Code:
is this path exist:-
/usr/xpg4/bin/awk

use this command to check

which /usr/xpg4/bin/awk

if exist use it; if not well do nothing :)
BR

# 12  
Old 06-15-2009
Quote:
Originally Posted by sylvainkalache
Thanks but this one do not work for me...


By the way I am a newbie with awk because I just discover this tool, but I don't understand why if I change a little my configuration file, the result is not ok.


Conf file:

Code:
interface FastEthernet0/0
 ip address 192.168.2.81 255.255.255.0
 duplex auto
 speed auto
 shutdown
!
interface FastEthernet1/0
 ip address 192.168.3.91 255.255.255.0
 shutdown
 duplex auto
 speed auto
!

It show:

Code:
is downernet0/0
is downernet1/0

It use awk and not nawk but I don't think it change something for this case...

If I good undestand this if awk find a line with the word interface it will stock the second word of the line in the variable inter and if it find the word shutdown before find another inter display the message with print:

Code:
nawk '/^interface/ {inter=$2;next}/shutdown/{print inter " is down"}' myConfig

why is this wrong?
both 'interfaces' have the 'shutdown' record......
How do you determine which is right or/wrong?
More description is needed.
# 13  
Old 06-15-2009
Quote:
Originally Posted by ahmad.diab
Code:
is this path exist:-
/usr/xpg4/bin/awk

use this command to check

which /usr/xpg4/bin/awk

if exist use it; if not well do nothing :)
BR

No I have check before, no way Smilie


Quote:
why is this wrong?
both 'interfaces' have the 'shutdown' record......
How do you determine which is right or/wrong?
More description is needed.
Is say is wrong because it should display:

interface FastEthernet0/0 is down
interface FastEthernet1/0 is down


and it display:

is downernet0/0
is downernet1/0


In reality there is just a problm with the print...
# 14  
Old 06-16-2009
Code:
awk 'BEGIN{ RS="[!]"}
NF && /shutdown/{  
 gsub(/ ip.*/,"is shutdown")
 print 
} ' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl to extract information from a file line by line

In the below perl code I am using tags within each line to extract certain information. The tags that are used are: STB >0.8 is STRAND BIAS otherwise GOOD FDP is the second number GO towards the end of the line is read into an array and the value returned is outputed, in the first line that... (1 Reply)
Discussion started by: cmccabe
1 Replies

2. Shell Programming and Scripting

HELP: Shell Script to read a Log file line by line and extract Info based on KEYWORDS matching

I have a LOG file which looks like this Import started at: Mon Jul 23 02:13:01 EDT 2012 Initialization completed in 2.146 seconds. -------------------------------------------------------------------------------- -- Import summary for Import item: PolicyInformation... (8 Replies)
Discussion started by: biztank
8 Replies

3. Shell Programming and Scripting

Search for a pattern,extract value(s) from next line, extract lines having those extracted value(s)

I have hundreds of files to process. In each file I need to look for a pattern then extract value(s) from next line and then search for value(s) selected from point (2) in the same file at a specific position. HEADER ELECTRON TRANSPORT 18-MAR-98 1A7V TITLE CYTOCHROME... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

4. Shell Programming and Scripting

Extract Line and Column from CSV Line in ksh or bash format

Hi, I was doing some research and can't seem to find anything. I'm trying to automate a process by creating a script to read a csv line and column and assigning that value to a variable for the script to process it. Also if you could tell me the line and column if it's on another work ... (3 Replies)
Discussion started by: vpundit
3 Replies

5. Shell Programming and Scripting

extract a line from a file by line number

Hi guys, does anyone know how to extract(grep) a line from the file, if I know the line number? Thanks a lot. (9 Replies)
Discussion started by: aoussenko
9 Replies

6. Shell Programming and Scripting

get the fifth line of a text file into a shell script and trim the line to extract a WORD

FOLKS , i have a text file that is generated automatically of an another korn shell script, i want to bring in the fifth line of the text file in to my korn shell script and look for a particular word in the line . Can you all share some thoughts on this one. thanks... Venu (3 Replies)
Discussion started by: venu
3 Replies

7. Shell Programming and Scripting

Extract the value from a line

hi, I need to get a particular word (marked in RED)from the below line. 3\fr01 \fr01 \fr01 \fr01 \10\0 Please suggest me with the command (10 Replies)
Discussion started by: sreelu
10 Replies

8. Shell Programming and Scripting

extract line by line from file

hi dudes, I have a text file in the below format 1 s sanity /u02 2 r script1 /u02 3 s sanity /u02 Please tell me a script to read this file line by line, I wrote the below script , but it is printing only 1st line not printing rest... (7 Replies)
Discussion started by: shirdi
7 Replies

9. Shell Programming and Scripting

extract a line from a file using the line number

Hello, I am having trouble extracting a specific line from a file when the line number is known. My first attempt involved grep -n 'hi' (the word 'hi will always be there) to get the line number before the line that I actually want (line 4). Extra Notes: -I am working in a bash script. -The... (7 Replies)
Discussion started by: grandtheftander
7 Replies

10. Shell Programming and Scripting

Extract a line from a file using the line number

I have a shell script and want to assign a value to a variable. The value is the line exctrated from a file using the line number. The line number it is not fix, and could change any time. I have tried sed, awk, head .. See my script # Get randome line number from the file #selectedline = `awk... (1 Reply)
Discussion started by: zambo
1 Replies
Login or Register to Ask a Question