Fetch Valid String


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Fetch Valid String
# 1  
Old 12-05-2013
Fetch Valid String

Hi All,

How to fetch the particular row based on my search command. For example

Source Column
Code:
Column A Column B
 
001,56123456
002,57123456
003,123456

Expected Output:
Code:
003,123456

To get this output I tried below mentioned function
Code:
grep '123456' filename.txt

but I got all three rows. I need to fetch only the particular rows from my source file. Please guide me how can I do that.

Thanks

Suresh

Last edited by Scott; 12-05-2013 at 10:25 AM.. Reason: Code tags, please...
# 2  
Old 12-05-2013
Code:
$ awk -F, '$2 == search' search="123456" filename.txt

# 3  
Old 12-05-2013
try also:
Code:
sed -n '/\b123456\b/p' infile

# 4  
Old 12-05-2013
Code:
#!/usr/bin/env perl
use strict;
use warnings;

while(<>){
	my @sp = split(/,/ , $_);	
	print if $sp[1] == 123456; 
}

# 5  
Old 12-06-2013
Really thanks to everyone for your right time help
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

To Fetch values from String

Dears, I have string like below in my csv file <someTechnicalDetails><someTechnicalDetails>HSI</someTechnicalDetails,1234564 <someTechnicalDetails><someTechnicalDetails>Voice</someTechnicalDeta,12345673 <someTechnicalDetails><someTechnicalDetails>IPTV</someTechnicalDetai,12345673 and I... (2 Replies)
Discussion started by: mirwasim
2 Replies

2. Shell Programming and Scripting

Check if a string is a valid timestamp in UNIX.

Hi all, I have date and time value in a string, I want to check if it is a valid date and time. Need help on this. Thanks (7 Replies)
Discussion started by: Pratiksha Mehra
7 Replies

3. Shell Programming and Scripting

Cut & Fetch word from string

I have a file with some SQL query, I want to fetch only Table Name from that file line by line. INPUT FILE SELECT * FROM $SCHM.TABLENAME1; ALTER TABLE $SCHM.TABLENAME1 ADD DateOfBirth date; INSERT INTO $SCHM.TABLENAME1 (CustomerName, Country) SELECT SupplierName, Country FROM $SCHM.TABLENAME2... (2 Replies)
Discussion started by: Pratik Majithia
2 Replies

4. Shell Programming and Scripting

Determine the string is valid

Dear All, I have a string "1234567899*0#123456789#", it can be divided into: - 1st: 1234567899 Validation: 10 digits, only 0-9 - 2nd: *0# Fixed Value - 3rd: 123456789 Validation: 9 digits, only 0-9 - 4th: # Fixed Value Would like to know if any 1 line statement perl,... (5 Replies)
Discussion started by: jimmy_y
5 Replies

5. Shell Programming and Scripting

How to fetch a string between two different strings?

Hi I am having a file with content as, <name>usrname</name> <value>ravistej</value> <name>pswd</name> <value>asdfgzxcv</value> . . . . <name>abc</name> <value>xyz</value> From this file, i want to fetch the string present between '<value>' and '</value>' and store the values into... (9 Replies)
Discussion started by: tejastrikez
9 Replies

6. Shell Programming and Scripting

Whether a string is a valid unix command

How to find a string which is entered in command promt is a valid unix command or not?. Thanks in advance ~Saravana (2 Replies)
Discussion started by: tsaravanan
2 Replies

7. Shell Programming and Scripting

Need to get next valid date from date string

Hi, I am passing date string of format 'YYYYMMDD' to a ksh script. Will I be able to get next valid date from the passed in string. Example I pass '20100228' to the shell script, Is there a reverse date command to get '20100301' .i.e to convert '20100228' to date and get next date.... (5 Replies)
Discussion started by: bittoo
5 Replies

8. Shell Programming and Scripting

Fetch the rows with match string on a fixed lenth text file - NO delimiters

Hi I am trying to fetch the rows with match string "0000001234" Input file looks like below: 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1... (6 Replies)
Discussion started by: nareshk
6 Replies

9. Shell Programming and Scripting

How to fetch variable value in if block and to compare it with certain string

Hi, I am trying to execute this command if ; then but getting error .Some problem with reteriving the value of $exception_info. Please help.Its urgent. thanks (4 Replies)
Discussion started by: khushboo
4 Replies

10. Shell Programming and Scripting

fetch string and insert later

"are you billy_smith ?" replace with "are you billy_smith ? my name is billy_smith" how to fetch the name "billy_smith" and using it later I need sed script to do this, any one can help? Thanks (6 Replies)
Discussion started by: playinmel.com
6 Replies
Login or Register to Ask a Question