Extract single word from lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract single word from lines
# 1  
Old 03-17-2010
Extract single word from lines

Hi I have a huge line like the following:
this word and many other words AA122134 other and other words and AA224466 and other other other other word AA667210 words

I only want extract the words AA?????? and put them in a column, how could i do ?
thx so much!
# 2  
Old 03-17-2010
MySQL

See the following code:
Code:
sed 's/ /\n/g' data | grep "^AA" | tr "\n" " "

[OR]
Code:
cat data | tr " " "\n"| sed -n '/^AA/p' | tr "\n" " "

[OR]
Code:
egrep -wo --color "AA[^ ]*?" data | tr "\n" " "


Last edited by ungalnanban; 03-17-2010 at 08:32 AM.. Reason: adding more ways to achive the requirement
# 3  
Old 03-17-2010
OK ! Smilie
# 4  
Old 03-17-2010
Try this,

Code:
cat file  | tr ' ' '\n' | sed -rne "/(AA[0-9]{6})/P" | tr "\n" " "


Last edited by Nila; 03-17-2010 at 08:36 AM..
# 5  
Old 03-17-2010
Or shorter:
Code:
awk '/^AA*/' RS=" " file

# 6  
Old 03-17-2010
Try:

Code:
perl -lane '$,="\n"; print grep {/AA\d+/} @F' file

or,

sed 's/[a-z]*//g' file | xargs -n1

# 7  
Old 03-17-2010
Code:
egrep -wo "AA[0-9]{6}" infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count same word which has come many times in single lines & pars

can i get a simple script for , Count same word which has come many times in single lines & pars Eg file would be == "Thanks heman thanks thanks Thanks heman thanks man" So resullt should be Thanks = 5 heman=2 man = 1 thanks in advance :) Please use code tags for code and... (1 Reply)
Discussion started by: heman96
1 Replies

2. UNIX for Dummies Questions & Answers

[Solved] How to extract single and duplicate lines from file?

Hi, I need help! I have two files, one containing a list of codes and the other a list of codes and their meaning. I need to extract from file 2 all the codes from file 1 into a new file. These are my files: File1: Metbo Metbo Memar Mth Metbo File2: Metbo Methanoculleus... (3 Replies)
Discussion started by: Lokaps
3 Replies

3. Shell Programming and Scripting

Search for a pattern,extract value(s) from next line, extract lines having those extracted value(s)

I have hundreds of files to process. In each file I need to look for a pattern then extract value(s) from next line and then search for value(s) selected from point (2) in the same file at a specific position. HEADER ELECTRON TRANSPORT 18-MAR-98 1A7V TITLE CYTOCHROME... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

4. Shell Programming and Scripting

Sed/awk to delete single lines that aren't touching other lines

Hello, I'm trying to figure out how to use sed or awk to delete single lines in a file. By single, I mean lines that are not touching any other lines (just one line with white space above and below). Example: one two three four five six seven eight I want it to look like: (6 Replies)
Discussion started by: slimjbe
6 Replies

5. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

6. Shell Programming and Scripting

extract whole thing in word, leaving behind last word. - perl

Hi, i've a string /u/user/DTE/T_LOGS/20110622_011532_TEST_11_HD_120/HD/TESi T_11_HD_120/hd-12 i need to get string, like /u/user/DTE/T_LOGS/20110622_011532_TEST_11_HD_120/HD the words from HD should get deleted, i need only a string till HD, i dont want to use any built in... (4 Replies)
Discussion started by: asak
4 Replies

7. Shell Programming and Scripting

Search the word to be deleted and delete lines above this word starting from P1 to P3

Hi, I have to search a word in a text file and then I have to delete lines above from the word searched . For eg suppose the file is like this: Records P1 10,23423432 ,77:1 ,234:2 P2 10,9089004 ,77:1 ,234:2 ,87:123 ,9898:2 P3 456456 P1 :123,456456546 P2 abc:324234 (2 Replies)
Discussion started by: vsachan
2 Replies

8. Shell Programming and Scripting

Break lines up into single lines after each space in every line

It sounds a bit confusing but what I have is a text file like the example below (without the Line1, Line2, Line3 etc. of course) and I want to move every group of characters into a new line after each space. Example of text file; line1 .digg-widget-theme2 ul { background: rgb(0, 0, 0) none... (7 Replies)
Discussion started by: lewk
7 Replies

9. Shell Programming and Scripting

Word count of lines ending with certain word

Hi all, I am trying to write a command that can help me count the number of lines in the /etc/passwd file ending in bash. I have read through other threads but am yet to find one indicating how to locate a specifc word at the end of a line. I know i will need to use the wc command but when i... (8 Replies)
Discussion started by: warlock129
8 Replies

10. Shell Programming and Scripting

Extract single or multi word string in Cshell

I am using the following code: set LASInputFile = `ls *. | head -1` set COMPLine = `grep -i :COMPANY $LASInputFile` to extract the following line from my input file: COMP. XYZ Public Company :COMPANY NAME I now need to extract the full name of the company which... (15 Replies)
Discussion started by: phudgens
15 Replies
Login or Register to Ask a Question