awk out an unknown column ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk out an unknown column ?
# 8  
Old 08-05-2008
aigles,

Works perfectly!! Very quick! This is exactly what I needed -- Thanks!

Now for the really difficult question how does it work?
About all that I can figure out from the man page is -n will "Suppresses the default output". I know the standard sed functions but I can't look at this and tell what it is doing.
# 9  
Old 08-05-2008
$PKG=XXXpkg8
VER=$( sed -n "/XXXpkg8/s/.*XXXpkg8\([^)]*).*/\1/p' )

Code:
sed -n                      Suppress automatic print, output must be explicit (p command)
/XXXpkg8/                   Select lines containing XXXpkg8
s/.*XXXpkg8\([^)]*).\).*/   Substitute all the line, memorize version XXXpkg8(version)
/\1/                        with memorized version
p                           Print the result if a substitution have been made

Jean-Pierre.
# 10  
Old 08-05-2008
Thanks JP!
# 11  
Old 08-05-2008
grep "XXXpkg8(5.7.0.10)" /tmp/trash
echo $?
if its = 0 then u found the pattern and the file.

Is this is what u r looking for?

Last edited by sudhamacs; 08-06-2008 at 11:32 AM..
# 12  
Old 08-06-2008
Quote:
Originally Posted by sudhamacs
grep "XXXpkg8(5.7.0.10)" /tmp/trash
echo $?
if its >0 then u found the pattern and the file.

Is this is what u r looking for?
No! If file exist and if pattern is found, the exit status is 0.

Jean-Pierre.
# 13  
Old 09-16-2008
Quote:
Originally Posted by aigles
$PKG=XXXpkg8
VER=$( sed -n "/XXXpkg8/s/.*XXXpkg8\([^)]*).*/\1/p' )

Code:
sed -n                      Suppress automatic print, output must be explicit (p command)
/XXXpkg8/                   Select lines containing XXXpkg8
s/.*XXXpkg8\([^)]*).\).*/   Substitute all the line, memorize version XXXpkg8(version)
/\1/                        with memorized version
p                           Print the result if a substitution have been made

Jean-Pierre.
Aigles,

Thanks for providing the breakdown but I still can't translate this to not look for the version in XXXpkg8(version)....
IE how would I do this same task if all I wanted in the output was XXpkg8(version) ....

Thanks!
# 14  
Old 09-17-2008
The parentheses \(...\) select what is being memorized as \1. The parentheses don't affect what is being matched (in this particular case) so you can move them around in the expression. If you have multiple parenthesized expressions, they will be remembered in \1 \2 etc according to the order of the opening parentheses.

The "select" part of the script is actually redundant, since the substitution obviously can only take place on lines where the left-hand side of the substitution expression matches.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script to append suffix to column when column has duplicated values

Please help me to get required output for both scenario 1 and scenario 2 and need separate code for both scenario 1 and scenario 2 Scenario 1 i need to do below changes only when column1 is CR and column3 has duplicates rows/values. This inputfile can contain 100 of this duplicated rows of... (1 Reply)
Discussion started by: as7951
1 Replies

2. Shell Programming and Scripting

awk to Sum columns when other column has duplicates and append one column value to another with Care

Hi Experts, Please bear with me, i need help I am learning AWk and stuck up in one issue. First point : I want to sum up column value for column 7, 9, 11,13 and column15 if rows in column 5 are duplicates.No action to be taken for rows where value in column 5 is unique. Second point : For... (1 Reply)
Discussion started by: as7951
1 Replies

3. Shell Programming and Scripting

awk to update unknown value in file using range of another

I am trying to use awk to update all the unknown values in $6 of file2, if the $4 value in file 2 is within the range of $1 of file1. If there is already a value in $6 other then unknown, it is skipped and the next line is processed. In my awk attempt below the final output is 6 tab-delimited... (6 Replies)
Discussion started by: cmccabe
6 Replies

4. Shell Programming and Scripting

Print Unknown Number of User Inputs in awk

Hello, I am new to awk and I am trying to figure out how to print an output based on user input. For example: ubuntu:~/scripts$ steps="step1, step2, step3" ubuntu:~/scripts$ echo $steps step1, step2, step3 I am playing around and I got this pattern that I want: ... (3 Replies)
Discussion started by: tattoostreet
3 Replies

5. Shell Programming and Scripting

Problems with awk (fatal error) and paste (two variables into one column-by-column)

Hello, I have a script extracting columns of useful numbers from a data file, and manipulating the numbers with awk commands. I have problems with my script... 1. There are two lines assigning numbers to $BaseForAveraging. If I use the commented line (the first one) and let the second one... (9 Replies)
Discussion started by: vgbraymond
9 Replies

6. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

7. Shell Programming and Scripting

awk code to ignore the first occurence unknown number of rows in a data column

Hello experts, Shown below is the 2 column sample data(there are many data columns in actual input file), Key, Data A, 1 A, 2 A, 2 A, 3 A, 1 A, 1 A, 1 I need the below output. Key, Data A, 2 A, 2 A, 3 A, 1 A, 1 A, 1 (2 Replies)
Discussion started by: ks_reddy
2 Replies

8. Shell Programming and Scripting

for each different entry in column 1 extract maximum values from column 2 in unix/awk

Hello, I have 2 columns (1st column has multiple entries but the corresponding values in the column 2 may be the same or different.) however I want to extract unique values for each entry in column 1 by assigning the max value from column 2 SDF4 -0.211654 SDF4 0.978068 ... (1 Reply)
Discussion started by: Diya123
1 Replies

9. Shell Programming and Scripting

Dropping Records for unknown reason in awk script

Hi, I have written the following it is pretty sloppy but I don't see any reason why I should be losing 54 records from a 3.5 million line file after using it. What I am doing: I have a 3.5 million record file with about 80,000 records need a correction. They are missing the last data from... (8 Replies)
Discussion started by: mkastin
8 Replies

10. Solaris

PING - Unknown host 127.0.0.1, Unknown host localhost - Solaris 10

Hello, I have a problem - I created a chrooted jail for one user. When I'm logged in as root, everything work fine, but when I'm logged in as a chrooted user - I have many problems: 1. When I execute the command ping, I get weird results: bash-3.00$ usr/sbin/ping localhost ... (4 Replies)
Discussion started by: Przemek
4 Replies
Login or Register to Ask a Question