Remove specific word from data contents problem asking


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove specific word from data contents problem asking
# 1  
Old 05-13-2010
Remove specific word from data contents problem asking

Hi,
Below is my input file:
Code:
>tempZ_1
SAFSDAFDSG
GGERRTTZZZ
ZASRARARET
WETPOASDAZ
ZZZASASFAS

>temp_9
ASAEGPIOEO
EIOPIZZZAS
FDFGZZZARA
ESEAZZZAAS
.
.

Desired output file:
Code:
>tempZ_1
SAFSDAFDSG
GGERRTTASR
ARARETWETP
OASDAASASF
AS

>temp_9
ASAEGPIOEO
EIOPIASFDF
GARAESEAAA
S
.
.

My purpose is want to delete all the "Z" from the input file's content.
I got try the following command:
Code:
sed 's///g' input_file
>tempZ_1
SAFSDAFDSG
GGERRTT
 ASRARARET
WETPOASDA
   ASASFAS

>temp_9
ASAEGPIOEO
EIOPI   AS
FDFG   ARA
ESEA   AAS
.
.

It still can't archive my desired goal Smilie
Thanks for any advice.
# 2  
Old 05-13-2010
I take it you want to delete any line that has a "Z" in it?
Code:
# sed '/Z/d' inputfile
or 
awk '!/Z/' inputfile

# 3  
Old 05-13-2010
Hi,

Thanks for your suggestion.
I just test your code suggestion.
It seems like it will delete all line that include 'Z' word instead of just delete 'Z' word only?
Thanks.
# 4  
Old 05-13-2010
Code:
awk 'END { say(_) }        
NR == 2 { l = length } 
/^>/ { 
  _ && say(_); _ = z 
  print; next 
  }
{ _ = _ ? _ $0 : $0 }
func say(x) {
    gsub(/Z/, z, x) 
    while (match(x, /........../)) {
      print substr(x, RSTART, RLENGTH)
      x = substr(x, RLENGTH + 1)
        }
    if (x) printf "%s\n\n", x
    }' infile

# 5  
Old 05-13-2010
Okay - now I understand - just delete the word not the line
Code:
awk '{for(i=1; i<= NF; i++) 
         { if( match($i, /Z/)
              {next}; 
           printf("%s ", $i)}; print ""}' inputfile >newfile

# 6  
Old 05-13-2010
Code:
$ while read line; do
> if ! echo $line | grep -o "^>.*" >/dev/null; then
> echo $line | sed 's/Z//g'
> else
> echo $line
> fi
> done <infile.dat
>tempZ_1
SAFSDAFDSG
GGERRTT
ASRARARET
WETPOASDA
ASASFAS

>temp_9
ASAEGPIOEO
EIOPIAS
FDFGARA
ESEAAAS
$

Simply type ">newfile.dat" after "<infile.dat" if you want to redirect the output in a new file instead of only printing it on screen.

Edit: Looks like I missed something Smilie

Last edited by pseudocoder; 05-13-2010 at 07:26 AM..
# 7  
Old 05-13-2010
or
Code:
tr -d "Z\n" <infile |fold -w 10

HTH
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search for a specific word and print only the word from the input file

Hi, I have a sample file as shown below, I am looking for sed or any command which prints the complete word only from the input file. Ex: $ cat "sample.log" I am searching for a word which is present in this file We can do a pattern search using grep but I need to cut only the word which... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

2. Shell Programming and Scripting

How to print multiple specific column after a specific word?

Hello.... Pls help me (and sorry my english) :) So I have a file (test.txt) with 1 long line.... for example: isgc jsfh udgf osff 8462 error iwzr 653 idchisfb isfbisfb sihfjfeb isfhsi gcz eifh How to print after the "error" word the 2nd 4th 5th and 7th word?? output well be: 653 isfbisfb... (2 Replies)
Discussion started by: marvinandco
2 Replies

3. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

4. Shell Programming and Scripting

Fetch entries in front of specific word till next word

Hi all I have following file which I have to edit for research purpose file:///tmp/moz-screenshot.png body, div, table, thead, tbody, tfoot, tr, th, td, p { font-family: &quot;Liberation Sans&quot;; font-size: x-small; } Drug: KRP-104 QD Drug: Placebo Drug: Metformin|Drug:... (15 Replies)
Discussion started by: Priyanka Chopra
15 Replies

5. Shell Programming and Scripting

Help with replace column data with specific word

Input file: Populus_trichocarpa 30 0 50 0 0 US Vitis_vinifera 1 18 2 8 6 US Populus_trichocarpa 1 5 100 0 0 US Arabidopsis_lyrata_subsp._lyrata 0 90 0 0 0 US Glycine_max 0 2 3 0 70 UK Desired output file: Populus_trichocarpa YES NO YES NO NO US Vitis_vinifera YES YES YES YES YES US... (4 Replies)
Discussion started by: perl_beginner
4 Replies

6. UNIX for Dummies Questions & Answers

How to print line starts with specific word and contains specific word using sed?

Hi, I have gone through may posts and dint find exact solution for my requirement. I have file which consists below data and same file have lot of other data. <MAPPING DESCRIPTION ='' ISVALID ='YES' NAME='m_TASK_UPDATE' OBJECTVERSION ='1'> <MAPPING DESCRIPTION ='' ISVALID ='NO'... (11 Replies)
Discussion started by: tmalik79
11 Replies

7. Shell Programming and Scripting

Exclude specific word from input file problem asking...

Hi, Below is my input file and desired output file: Input file: >header_N_1 ASFDGDGNDGEGWETWRYWTETWNETOWETWETWNETTETNWET . . Desired output file: >header_N_1 ASFDGDGDGEGWETWRYWTETWETOWETWETWETTETWET . . From the input file, I just hope to exclude the 'N' word from its content... (5 Replies)
Discussion started by: patrick87
5 Replies

8. Shell Programming and Scripting

Extract specific content from data and rename its header problem asking

Input file 1: >pattern_5 GAATTCGTTCATGTAGGTTGASDASFGDSGRTYRYGHDGSDFGSDGGDSGSDGSDFGSDF ATTTAATTATGATTCATACGTCATATGTTATTATTCAATCGTATAAAATTATGTGACCTT SDFSDGSDFKSDAFLKJASLFJASKLFSJAKJFHASJKFHASJKFHASJKFHSJAKFHAW >pattern_1 AAGTCTTAAGATATCACCGTCGATTAGGTTTATACAGCTTTTGTGTTATTTAAATTTGAC... (10 Replies)
Discussion started by: patrick87
10 Replies

9. Shell Programming and Scripting

Remove specific pattern header and its content problem facing

Input file: >TRACK: Position: 1 TYPE: 1 Pos: SVAVPQRHHPGGTVFREPIIIPAIPRLVPGWNKPIIIGRHAFGDQYRATDRVIPGPGKLE LVYTPVNGEPETVKVYDFQGGGIAQTQYNTDESIRGFAHASFQMALLKGLPLYMSTKNTI LKRYDGRFKDIFQEIYESTYQKDFEAKNLWYEHRLIDDMVAQMIKSEGGFVMALKNYDGD >TRACK: Position: 1 TYPE: 2 Pos: FAHASFQMALLKGLPLYMS... (8 Replies)
Discussion started by: patrick87
8 Replies

10. Shell Programming and Scripting

Remove a non-specific word froma file

Hi All, I am encountering a problem while removing a string from a file. Actually, i have done this thing before using sed to replace the word but this time word is not specfic. its value is changing with each file. e.g. %HD% Serial Number list per DN required. +3... (2 Replies)
Discussion started by: apjneeraj
2 Replies
Login or Register to Ask a Question