String search and return value from column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting String search and return value from column
# 1  
Old 01-12-2008
String search and return value from column

Dear All

I had below mention file as my input file.

87980457 Jan 12 2008 2:00AM 1 60 BSC1
81164713 Jan 12 2008 3:00AM 1 60 BSC2
78084521 Jan 12 2008 4:00AM 1 60 BSC3
68385193 Jan 12 2008 5:00AM 1 60 BSC4
85883305 Jan 12 2008 6:00AM 1 60 BSC5
75069865 Jan 12 2008 7:00AM 1 60 BSC6

Now i want to search BSC4 word in that file and if it match in file then i want to take its date from same file mention in left side.

I.E. If BSC4 match then it should returen Jan 12 2008 5:00AM from same file.

Sugest me possible way.

Regards
jaydeep
# 2  
Old 01-12-2008
$ awk '/BSC4/ {print $2,$3,$4,$5}' jaydeep.out
Jan 12 2008 5:00AM
# 3  
Old 01-12-2008
Code:
#/bin/ksh

read value?"Enter the value to search for: "

awk -v val=$value '$8 == val  { printf("%s %s %s %s\n", $2, $3, $4, $5) }' infile

# 4  
Old 01-12-2008
Code:
awk '/BSC4/{$1=$6=$7=$NF="";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

Search a column a return a set of words

Hi I have two files. One is a text file consisting of sentences i.e. INPUT.txt and the second file is SEARCH.txt consisting of two or three columns. I need help to write a script to search the second column of SEARCH.txt for each set of five words (blue color as set one and green color as set... (6 Replies)
Discussion started by: my_Perl
6 Replies

2. UNIX for Advanced & Expert Users

Recursively search the string from a column in no. of files

i have a file named keyword.csv(contains around 8k records) which contains a no. of columns. The 5th column contains all the keywords. I want to recursively search these keywords in all .pl files(around 1k) and display the filename....Afterthat i will use the filename and some of the column from... (3 Replies)
Discussion started by: millan
3 Replies

3. Shell Programming and Scripting

bash: need to have egrep to return a text string if the search pattern has NOT been found

Hello all, after spending hours of searching the web I decided to create an account here. This is my first post and I hope one of the experts can help. I need to resolve a grep / sed / xargs / awk problem. My input file is just like this: ----------------------------------... (6 Replies)
Discussion started by: bash4ever
6 Replies

4. Shell Programming and Scripting

search a string in a particular column of file and return the line number of the line

Hi All, Can you please guide me to search a string in a particular column of file and return the line number of the line where it was found using awk. As an example : abc.txt 7000,john,2,1,0,1,6 7001,elen,2,2,0,1,7 7002,sami,2,3,0,1,6 7003,mike,1,4,0,2,1 8001,nike,1,5,0,1,8... (3 Replies)
Discussion started by: arunshankar.c
3 Replies

5. Shell Programming and Scripting

How to search for string and return binary result?

Hi, I have a problem that I am sure someone will know the answer to. Currently I have a script which returns a binary output if it finds a certain search string (in this case relating to a DRBD cluster) as follows: searchstring="cs:Connected st:Primary/Secondary ds:UpToDate/UpToDate" && echo... (3 Replies)
Discussion started by: almightybunghol
3 Replies

6. UNIX for Dummies Questions & Answers

search for string and return substring

Hi, I have a file with the following contents: I need to create a script or search command that will search for this string 'ENDC' in the file. This string is unique and only occurs in one record. Once it finds the string, I would like it to return positions 101-109 ( this is the date of... (0 Replies)
Discussion started by: Lenora2009
0 Replies

7. UNIX for Dummies Questions & Answers

Search for string and return lines above and below

Hi, I have a file with the following contents: COMPANY ABCD TRUCKER JOE SMITH TRUCK 456 PLATE A12345678 TRUCKER BILL JONES TRUCK 789 PLATE B7894561 I need to create a script or search command that will search for this string '789' in the file. This string is unique and only... (7 Replies)
Discussion started by: doza22
7 Replies

8. Shell Programming and Scripting

Search in a column by a string

Hi All, My file looks like : hsdhj dsajhf jshdfajkh jksdhfj jkdhsfj shfjhd shdf hdsfjkh jsdfhj hdshf sdjh dhs foot dsjhfj jdshf dasfh jdsh dsjfh jdfshj david Now, I want to search entire column by a string... (10 Replies)
Discussion started by: naw_deepak
10 Replies

9. Shell Programming and Scripting

Search string and return only the 5th line

I have looked at almost every posting on here regarding, grep, sed, awk, nawk, perl methods to perform this function, but they are just not returning the results I hope to see. Example File: abcdef 123456 ghijkl 7890123 7890123 7890123 7890123 mnopqrs 456789 This is the most... (4 Replies)
Discussion started by: doza22
4 Replies

10. Shell Programming and Scripting

Search for string dublicates in column

Hi I have a file with one column. There are a few replicas in this column, that is some lines look exactly the same. I want to know the ones that occur twice. Inputfile.xml "AAH.dbEUR" "ECT.dbEUR" "AEGN.dbEUR" "AAH.dbEUR" "AKZO.dbEUR" ... Here I would like to be informed that... (7 Replies)
Discussion started by: lulle
7 Replies
Login or Register to Ask a Question