Getting 15 characters after search phrase


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting 15 characters after search phrase
# 1  
Old 07-08-2009
Getting 15 characters after search phrase

I have data that looks like this:

Code:
2002  140  40800.0060  GPS 20  C1  25477810.2305
2002  140  41100.0060  GPS 20  C1  25298056.0453

I need to get data after certain pattern.. for example if i search for C1
it should return

Code:
25477810.2305
25298056.0453

To achieve this, it should:

1) In the best scenario, if possible, it would start after the space/spaces that come after the search word, print the characters, and stop when space is found again

2) if that is not possible, other way would be to return 15 characters after the search pattern(after = the pattern itself would be excluded).

I tried with grep and sed, but could not get the results i wanted..

Thank you in advance!
# 2  
Old 07-08-2009
Your number strings are of length 13 not 15 in the sample you provided.
Code:
sed -n  's/^.*C1\([[:blank:]]\{1,\}\)\([0-9]\{8\}\.[0-9]\{4\}\).*$/\2/p'

# 3  
Old 07-08-2009
Code:
awk '
/C1/{
  for(i=1;i<=NF;i++){
     if($i == "C1"){
          print $(i+1)
     }
  }
}
' file

# 4  
Old 07-09-2009
Code:
sed 's/.*C1\(.*\)/\1/'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search avoiding special characters

Hi all, I have a list which I want to search in another file. I can do that using grep -f but the search is failing due to special characters, how do I solve this? One row in that list is amino-acid permease inda1 gb|EDU41782.1| amino-acid permease inda1 Input file to be searched... (2 Replies)
Discussion started by: gina.lizar
2 Replies

2. Shell Programming and Scripting

How to find a phrase and pull all lines that follow until the phrase occurs again?

I want to burst a report by using the page number value in the report header. Each section starts with *PAGE NO:* 1 Each section might have several pages, but the next section always starts back at 1. So I want to find the "*PAGE NO:* 1" value and pull all lines that follow until "*PAGE NO:* 1"... (4 Replies)
Discussion started by: Scottie1954
4 Replies

3. UNIX for Dummies Questions & Answers

[Solved] How to search for these escape characters?

echo "***Enter new LISTENER_PORT (only applicable to new instance), " I used the following: E486: Pattern not found: echo \"\*\*\*Enter new LISTENER_PORT \(only applicable to new instanace\), \" when I try to search for the above line, I'm not able to do it so how do I search for the... (5 Replies)
Discussion started by: jediwannabe
5 Replies

4. Shell Programming and Scripting

Code to search for a phrase and run a command

hi All, Am newbie to unix and would require your help to complete this task. Condition: I have a server start up script and I would like to append the code in such a way that it searches for a phrase "process completed" in taillog when server starts up and also should run another script... (9 Replies)
Discussion started by: fop4658
9 Replies

5. Shell Programming and Scripting

search for a set of characters and move

I want to search/grep for a set of characters in a file(all occurences) and move them to another file. Any command line? regards, Sri (2 Replies)
Discussion started by: Sriranga
2 Replies

6. Shell Programming and Scripting

Search a String for characters - or +

How would I accomplish this if I want to test to see if it 1) starts with a dash so something like "-R" AND 2) starts with 1 character then either a "-" or "+" and then up to 3 characters such as "a+rx" (3 Replies)
Discussion started by: mkjp2011
3 Replies

7. Shell Programming and Scripting

search and replace characters in one string

I have lines like: Dog Cat House Mouse Dog Cat House Mouse Dog Cat House Mouse Dog Cat House Mouse I'd like to replace characters only in $3. H -> Z s -> W e -> x Resulting in something like (where $1, $2, and $4 are not changed): Dog Cat ZouWx Mouse Dog Cat ZouWx Mouse... (3 Replies)
Discussion started by: dcfargo
3 Replies

8. Shell Programming and Scripting

Search For Control M characters in files

Hi , I have special character control M in many of my files as below ersNet-Telnet-3.03/Makefile.PL100644 21166 144 612 7113770214 135 77 0ustar jayusers## -*- Perl -*-^M ^M use ExtUtils::MakeMaker qw(WriteMakefile);^M ^M WriteMakefile(NAME => "Net::Telnet",^M ... (4 Replies)
Discussion started by: Mohammed
4 Replies

9. UNIX for Dummies Questions & Answers

search special characters in a file

Hello I am new to shell scripting and can anyone tell me how to check if there are any special characters in a file. Can i use grep ? thanks susie (2 Replies)
Discussion started by: cramya80
2 Replies

10. Shell Programming and Scripting

Best way to search files for non-printable characters?

I need to check ftp'd incoming files for characters that are not alphanumeric,<tab>, <cr>, or <lf> characters. Each file would have 10-20,000 line with up to 3,000 characters per line. Should I use awk, sed, or grep and what would the command look like to do such a search? Thanks much to anyone... (2 Replies)
Discussion started by: jvander
2 Replies
Login or Register to Ask a Question