- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how get two lines ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2011 06:22 AM
тАО02-21-2011 06:22 AM
this is the scenario .. i have a files whit this information
cat information.txt
uno- this is a cat
dos- this is a dog
uno- this is a cat
dos- this is a duck
uno- this is a cat
dos- this is a cat
uno- this is a dog
dos- this is a cat
uno- this is a duck
dos- this is a pig
uno- this is a pig
dos- this is a pig
I need to compare both lines toguehter.
if you see they are separated by a line, i need to see if the column 5 is the same or not for each two lines, how can i do that?
how can i get the lines uno- dos- after one line ?
i mean i need to get first:
uno- this is a cat
dos- this is a dog
how can i get them?
after i need to compare the column 5 , i know how to do that
then after a white line i need to get these lines ...
uno- this is a cat
dos- this is a duck
and go on ..
please let me know...
i think i can do it with awk, i do not know how exactly to use it to get the information as i need it ..
thanks in advace.
Manuales.
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2011 07:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2011 07:30 AM
тАО02-21-2011 07:30 AM
Re: how get two lines ...
how can i stop the first two lines to get the value of the column 3 ... and then stop for the other 2 and go on ..?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2011 07:41 AM
тАО02-21-2011 07:41 AM
Re: how get two lines ...
> how can i stop the first two lines to get the value of the column 3 ... and then stop for the other 2 and go on ..?
I'm not sure I understand what you are asking. If you want the third field and not the fifth, the logic would look like:
# awk 'NF==0 {next};{getline LINE;split(LINE,A);if ($3==A[3]) {print $0"\n"LINE}}'
This code skips blank lines (i.e those that have no fields: NF==0). Otherwise, we have the first line we want in '$0'. The next LINE is fetched with 'getline' into the 'LINE' variable. Since 'getline' doesn't do auto-field-spliiting, we do it with a 'split' ourselves.
Regards!
..JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2011 07:57 AM
тАО02-21-2011 07:57 AM
Re: how get two lines ...
for .....
what you told me:
awk 'NF==0 {next};{getline LINE;split(LINE,A);if ($5==A[5]) {print $0"\n"LINE}}' file.txt
a=column 5 from uno-
b=column 5 form dos_
if [[ $a = $b ]]
then
echo $ > output.txt
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2011 08:04 AM
тАО02-21-2011 08:04 AM
Re: how get two lines ...
> what you told me:
I don't understand what you are asking. Did you try running the code I suggested using *your* input as posted; and did it produce the output you wanted?
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2011 08:07 AM
тАО02-21-2011 08:07 AM
Re: how get two lines ...
once i have got the first 2 lines the script has to stop to get the value of the column 5 of the line where appears "uno_" and keep it in a variable a, then the script will get the
line where appears "dos_" , will keep the value in the variable b, then a and b will be compared, if they are similar $a will be send to an output file ....
then i need to do the same to the other two lines and go on ....
until the script has red all the file ..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2011 08:09 AM
тАО02-21-2011 08:09 AM
Re: how get two lines ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2011 08:14 AM
тАО02-21-2011 08:14 AM
Re: how get two lines ...
awk 'BEGIN { }
{
...................
..................
a=`echo $line that contains the word uno_ | cut -d" " -f`
b=`echo $line that contains the word dos_ | cut -d" " -f`
if [[ $a = $b ]]
then
echo $a > output.txt
fi
...................
..................
}
}' file
it is a loop of the code you gave me for each two lines uno_ and dos_
space
the the others lines uno_ and dos_
and go on ...
how can i do that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2011 08:22 AM
тАО02-21-2011 08:22 AM
Re: how get two lines ...
> once i have got the first 2 lines the script has to stop to get the value of the column 5 of the line where appears "uno_" and keep it in a variable a, then the script will get the
line where appears "dos_" , will keep the value in the variable b, then a and b will be compared, if they are similar $a will be send to an output file ....
Look at the 'awk' script I suggested. You said in your opening comments, "I think I can do it with awk...".
The script I have offered skips blank lines; reads two lines; and "stops" at that point if you want to think of it that way. The 5th field of one record is compared for equality to the 5th field of the second record just as you have asked. In the case of the 'awk' records, '$5' is one variable and 'a[5]' is the other.
Regards!
...JRF...