need help asap


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need help asap
# 1  
Old 06-17-2008
need help asap

i have a file having content
a|b|c
1|2|33
4|6|55
end
a|b|d
3|4|55
end
a|b|c
45|67|98
end

so i want to print 3rd field of header a|b|c and footer end.
e.g. o/p should be
33
55
98
# 2  
Old 06-17-2008
Code:
awk -F'|' '$1=="a"{f=1;next}{if(f==1)print $NF;f=0}' file

# 3  
Old 06-18-2008
AWK Problem

thanx danmero,

i have modified the answers a littel bit, and got the results set, but it's not disaplying the 2nd row of the 1st record set(record sets are lines between header and footer).

In order to avoid the confusion,i have changed the a.txt(chnaged one marked in red)
a|b|c
1|2|33
4|6|55
............
...........
end
a|b|d
3|4|559
.......
.......
end
a|b|c
45|67|98
7|8|90
4|6|89
.......
........
end
then
awk -F'|' '$3=="c" {f=1;next}{if(f==1)print $NF;f=0}' a.txt
o/p is
33
98
but it should be as follows for column c only
33
55
.....
......
98
90
89
.....
.....
again .....if i want to print only partiuclar record of record set then how to achieve it ????
let i want to only print c column's 2nd row only
so o/p should be ,2nd rows of any c columns record set i.e.
55
90
etc

Last edited by manas_ranjan; 06-18-2008 at 05:48 AM..
# 4  
Old 06-18-2008
An awkward script solution

This script will do what you need, but may not be efficient. Performance will be bad if the data file is too large.
Code:
parm=$1
marker=0
while read line 
do
 if [ $line = "a|b|c" ]
 then
  marker=1
  count=0
  continue
 fi 
 if [ $marker -eq 1 ]
 then
  if [ $line = "end" ]
  then
   marker=0
  else
   count=`expr ${count} + 1`
   if [ $count -eq $parm ]
   then
     echo $line | cut -d"|" -f 3
   fi
  fi
 fi
done<datafile

Save the above as myscript.ksh and pass one parameter, which is the number of line you want as output.

For example, if you want only 3rd column of 2nd record in each record set, invoke the script as
Code:
myscript.ksh 2


Last edited by krishmaths; 06-18-2008 at 09:16 AM..
# 5  
Old 06-18-2008
Quote:
Originally Posted by manas_ranjan
....if i want to print only partiuclar record of record set then how to achieve it ????
let i want to only print c column's 2nd row only
so o/p should be ,2nd rows of any c columns record set i.e.
55
90
Code:
awk -F'|' '$3=="c" {a=(NR + 2) ;next}{if(NR==a)print $NF}' a.txt


Last edited by danmero; 06-18-2008 at 10:45 AM.. Reason: correction
# 6  
Old 06-18-2008
dear krishmaths, no expected results :-( for
if i want to print only partiuclar record of record set then how to achieve it ????
let i want to only print c column's 2nd row only
so o/p should be ,2nd rows of any c columns record set i.e.
55
90

but appreciated your help and co-ordianation .

dear danmero,

it's not working :-( , o/p is
33
98

dear danmero/krishmaths
can you have a look on the above slight modified query ???

Last edited by manas_ranjan; 06-18-2008 at 10:39 AM..
# 7  
Old 06-18-2008
Sorry, I correct my previous post, should work now Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need a Python Script asap

I work on various messages received from server and want to write a python script that can sort messages with unique flag values and give me the output in a text file. I get these messages in the form of .zcap file from server and I use an internal tool to filter: Step 1) Zcap file to get... (1 Reply)
Discussion started by: Vijeta Laad
1 Replies

2. Homework & Coursework Questions

PLEASE HELP ME ASAP

can anyone help me with this??? make program ( shell script) to detect and display errors occurred in initializing a Unix system (4 Replies)
Discussion started by: dementor
4 Replies

3. Shell Programming and Scripting

Hello - Have a big issue need help please ASAP

I have been using this simple grep command to extract fields from a file that ALPHANUMERIC field has been set to 16 grep -w 'ALPHANUMERIC *16' filename ------------------------- sample data file SAMP_RICS "SAMPLE RICS" 5694 NULL ALPHANUMERIC 60 RMTES_STRING ... (11 Replies)
Discussion started by: mnassiri
11 Replies

4. Shell Programming and Scripting

Need ASAP an awk command

Input1 : "06:28:45 28.08.2010|SCHEDULE: Started program POSG1.PLK110 (#J2325) has completed successfully" or Input2 : "06:28:45 28.08.2010|SCHEDULE: Started program POSG1.PLK110 has completed successfully" Output :06:28:45 28.08.2010 08/27/10 Please give me an single awk command ASAP... (0 Replies)
Discussion started by: shanneykar
0 Replies

5. Shell Programming and Scripting

KERBEROS_V4 -help needed ASAP

#!/bin/sh HOST='ftp.bend.com' USER='temp1' PASSWD='temp2' FTPPATH='SY1:' ifile='concat.txt' #FTP concatenated file ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD binary cd $FTPPATH put $ifile get $ifile retrieval.$$ quit END_SCRIPT if then echo "FTP of... (2 Replies)
Discussion started by: Sgiri1
2 Replies

6. Shell Programming and Scripting

need help asap!

Hello everyone, I'm new to using Linux and i am trying to create a script that will produce a list of all the files of the present working directory. So far I only have this #!/bin/bash cd / ls -lt>> I can't figure out what I am suppose to do next. (6 Replies)
Discussion started by: reecygee
6 Replies

7. UNIX for Dummies Questions & Answers

I Need Some (help)answers Asap

can someone explain the meaning of the following shell commands: 1. who / wc -l 2. who / sort > user_names 3. cat students > new_students 4. current_day='date / cut -cl-3' i would also appreciated if you could tell me some things about the umask 1. what is a good umask value and why? 2.... (2 Replies)
Discussion started by: dakis
2 Replies

8. UNIX for Dummies Questions & Answers

HELP ASAP.. pretty simple..

Hey guys.... couple questions... I am working a problem set and can't answer this: 1) Suppose you are in a directory that contains a file called "foo." You want to create a new file called "bar" that contains the sorted contents of "foo" in the parent directory of the one you're in. How... (8 Replies)
Discussion started by: ugakid
8 Replies

9. UNIX for Dummies Questions & Answers

Sendmail - need help ASAP

Hi guys ! I have 24 hours to learn about sendmail (as much as I can) ... where to start ? where to go ? thnx, (2 Replies)
Discussion started by: Gismo
2 Replies

10. Shell Programming and Scripting

Need rm script help ASAP

I need your expertise anyone. I'm trying to remove part of a id # in a script. Reason, the part of the id is a underscore that is making my life impossible. I simply cannot handle all the requests and modify every single one in vi or edt. So I wanted to modify the script.. For example ... (12 Replies)
Discussion started by: simon2000
12 Replies
Login or Register to Ask a Question