I have a file on stdin that I want contains a bunch of lines that are
basically a dump from a flatfile database. I want to be able to match
a field in one of the lines and assign some of the other fields in the
same row to environment variables. The problem is that the database
is dumped with 2 lines for each row and it doesn't always insert a
newline after the same field. Is there a way in awk that I could join
the two lines, search for a pattern on say field2, then assign field5
and field7 to environment varialbes?
Say for example the the input is:
field1a field2a field3a field4a field5a \n
field6a field7a field8a field9a field10a
field1b field2b field3b field4b \n
field5b field6b field7b field8b field9b field10b
....
I've been doing it with in this fairly cumbersom way but I must think
that there's a much better way to do this all with an awk script.
Sorry, I'm still a newb at this stuff.
Thanks
LINE1=`lynx -dump $URL | sed '/^$/{ N ; /^\n$/D }' | cat -n | grep -i
$HOSTNAME`
LINENUM=`echo $LINE1 | awk '{print $1}'`
LINENUM=`expr $LINENUM + 1`
LINE2=`lynx -dump $URL | cat -n | sed 's/^ *//' | grep -i "^$LINENUM"`
LINE=`echo $LINE1 $LINE2 | sed -e '/.*/N' -e 's/\n/ /'`
echo
echo Rack: `echo $LINE | awk '{print $11}'`
echo Side: `echo $LINE | awk '{print $12}'`
echo Slot: `echo $LINE | awk '{print $13}'`
echo Asset Tag: `echo $LINE | awk '{print $2}'`
echo Machine name and IP: `echo $LINE | awk '{print $5 " " $6}'`
.................................................................
Posted via TITANnews - Uncensored Newsgroups Access
>>>> at http://www.TitanNews.com <<<<
-=Every Newsgroup - Anonymous, UNCENSORED, BROADBAND Downloads=-
|
|
0
|
|
|
|
Reply
|
Tyaan
|
11/14/2003 9:07:18 PM |
|
Tyaan <asdf@asdf.com> wrote:
> I have a file on stdin that I want contains a bunch of lines that are
> basically a dump from a flatfile database. I want to be able to match
> a field in one of the lines and assign some of the other fields in the
> same row to environment variables. The problem is that the database
> is dumped with 2 lines for each row and it doesn't always insert a
> newline after the same field. Is there a way in awk that I could join
> the two lines, search for a pattern on say field2, then assign field5
> and field7 to environment varialbes?
>
> Say for example the the input is:
>
> field1a field2a field3a field4a field5a \n
> field6a field7a field8a field9a field10a
> field1b field2b field3b field4b \n
> field5b field6b field7b field8b field9b field10b
> ...
1. while read a; do
line="$line $a" ;;
case "$a" in
*[^n]) echo $line; line='' ;;
esac
done
2. echo 'g/\\n$/ \
.,/[^n]$/j
wq' | ed file
You still have to get rid of '\n'.
--
William Park, Open Geometry Consulting, <opengeometry@yahoo.ca>
Linux solution for data management and processing.
|
|
0
|
|
|
|
Reply
|
William
|
11/15/2003 3:52:55 AM
|
|
|
1 Replies
451 Views
(page loaded in 0.064 seconds)
Similiar Articles: Join two lines in pattern matching, search, then assign fields to ...... pattern matching, search, then assign fields to ... split at a pattern - comp.lang.awk Join two lines in pattern matching, search, then assign fields to ... The variables ... find string matching whole word - comp.soft-sys.matlabJoin two lines in pattern matching, search, then assign fields to ... find string matching whole word - comp.soft-sys.matlab For example, here are two of our variables ... Assigning same value to multiple variables - comp.lang.rexx ...Join two lines in pattern matching, search, then assign fields to ..... lines and assign some of the other fields in the same row to environment variables. ... matching ... Environment variables in an awk script - comp.lang.awkJoin two lines in pattern matching, search, then assign fields to ..... of the lines and assign some of the other fields in the same row to environment variables ... passing awk variable to shell variable - comp.lang.awkJoin two lines in pattern matching, search, then assign fields to ..... variables. The problem is that the database is dumped with 2 lines for each row and it doesn't ... print columns from bash variable - comp.lang.awkOne solution here could be to > create two shell variables in ... Join two lines in pattern matching, search, then assign fields to ... print columns from bash variable ... print lines between two patterns - comp.lang.awkJoin two lines in pattern matching, search, then assign fields to ... Is there a way in awk that I could join the two lines, search for a pattern on say field2 ... echo ... gawk problem matching multiple patterns ?!? HOW-TO? - comp.lang ...Join two lines in pattern matching, search, then assign fields to ... gawk problem matching multiple patterns ?!? HOW-TO? - comp.lang ... Join two lines in pattern ... Newline after xml tag - comp.soft-sys.sasJoin two lines in pattern matching, search, then assign fields to ... Newline after xml tag - comp.soft-sys.sas Join two lines in pattern matching, search, then assign ... split at a pattern - comp.lang.awkJoin two lines in pattern matching, search, then assign fields to ... Join two lines in pattern matching, search, then assign fields to ... split at a pattern - comp.lang ... Join two lines in pattern matching, search, then assign fields to ...... pattern matching, search, then assign fields to ... split at a pattern - comp.lang.awk Join two lines in pattern matching, search, then assign fields to ... The variables ... Perl: How do I match a string and also assign the match to another ...... input and try to match a regular expression (ONE|TWO). and then assign ... was how to match ay> pattern in a string variable and assign what ... ] ; then#code#line 42elif ... 7/20/2012 11:56:13 AM
|