Conditional removing of words from a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Conditional removing of words from a line
# 1  
Old 06-25-2011
Conditional removing of words from a line

Hi ,

I have a .csv file,from which I want to remove some data from each column as below.

Code:
Source Data

GT_12_AUDIT,SCHEDULED,NOZOMI2010/GT_12_AUDIT,CTSCAN/Zh_GT_6547887/GT_12_AUDIT,CTSCAN/Zh_GT_6547887
GT_12_13_AUDIT,SCHEDULED,NOZOMI2010/GT_12_13_AUDIT,XRAY/XT_TH_6987458/GT_12_13_AUDIT,XRAY/Zh_GT_6547887
GT_12_13_VISITED,SCHEDULED,NOZOMI2010/GT_12_13_VISITED,XRAY/XT_TH_6987458/GT_12_13_VISITED,XRAY/Zh_GT_6547887


Code:
Target Data

AUDIT,SCHEDULED,NOZOMI2010/AUDIT,CTSCAN/Zh_GT_6547887/AUDIT,CTSCAN/Zh_GT_6547887
AUDIT,SCHEDULED,NOZOMI2010/AUDIT,XRAY/XT_TH_6987458/AUDIT,XRAY/Zh_GT_6547887
VISITED,SCHEDULED,NOZOMI2010/VISITED,XRAY/XT_TH_6987458/VISITED,XRAY/Zh_GT_6547887

I really don't have any clue on how to do this, please give me some logic to do the same.

Regards,Deepti
# 2  
Old 06-26-2011
Try if this sed fills your requirment :
Code:
sed 's/\(GT_[0-9][0-9]_\)\|\(GT_[0-9][0-9]_[0-9][0-9]_\)//g'

# 3  
Old 06-27-2011
Hi Deepti,

u can try as below also...
Code:
sed 's/GT_12_13_//g; s/GT_12_//g' <file_name>

Smilie

Last edited by Franklin52; 06-27-2011 at 03:08 AM.. Reason: Please use code tags for code and data samples, thank you
# 4  
Old 06-27-2011
Alternate Sed
Code:
sed 's/GT_.._//g ; s/[0-9][0-9]_//g' inputfile > outfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace particular words in file based on if finds another words in that line

Hi All, I need one help to replace particular words in file based on if finds another words in that file . i.e. my self is peter@king. i am staying at north sydney. we all are peter@king. How to replace peter to sham if it finds @king in any line of that file. Please help me... (8 Replies)
Discussion started by: Rajib Podder
8 Replies

2. Shell Programming and Scripting

Add words in beginning , end after removing a word in a file

My file has the entries like below... /dev/sds /dev/sdak /dev/sdbc /dev/sdbu I want to make the file like below echo 1 > /sys/block/sds/device/rescan echo 1 > /sys/block/sdak/device/rescan echo 1 > /sys/block/sdbc/device/rescan echo 1 > /sys/block/sdbu/device/rescan (2 Replies)
Discussion started by: saravanapandi
2 Replies

3. Shell Programming and Scripting

sed conditional \n replace for each line

How could be removed \n only if appearing at position 80 in the line? (4 Replies)
Discussion started by: RomanF
4 Replies

4. Shell Programming and Scripting

removing the words with symbols in a file in unix

I have file like below Hi iam author <br>joseph</br> in france. I live in my home <br></br> but no food. I will play footbal <br></br> but i wont play cricket. I will read all the books <br>all fiction stories</br> i hate horror stories. I want output like below Hi iam author... (3 Replies)
Discussion started by: vinothsekark
3 Replies

5. Shell Programming and Scripting

conditional append one line in file.

Hi, Unix gurus, I have a requirement as following: checking existing file, if the file only contain one line. then append "No data" else keep existing file as is. can i achieve this by in command line without write a script. :wall: Thanks in advance. (4 Replies)
Discussion started by: ken002
4 Replies

6. Shell Programming and Scripting

finding and removing 2 identical consecutive words in a text

i want to write a shell script that correct a text file.for example if i have the input file: "john has has 2 apples anne has 3 oranges oranges" i want that the output file be like this: "john has 2 apples anne has 3 oranges" i've tried to read line by line from input text file into array... (11 Replies)
Discussion started by: cocostaec
11 Replies

7. Shell Programming and Scripting

Removing identical words in column

I have a file that needs to be cleaned up. Here is the file: Project Project John Project Gary Project Sean Project2 Project2 Lisa Project2 Tyler Project2 Sam Project3 Project3 Mike Project3 Bran I need the o/p to be: Project John Gary Sean Project2 (7 Replies)
Discussion started by: leepet01
7 Replies

8. Shell Programming and Scripting

removing 2 words from file.

Hi All, I have a text file with name of source files in that. source files ends with .mxml and .css. Now I want to remove the extensions of these source files. Currently I can do so by writing 2 sed commands, as there are files with just 2 different extensions. But I want to do it in one sed... (6 Replies)
Discussion started by: mkashif
6 Replies

9. Shell Programming and Scripting

Copying x words from end of line to specific location in same line

Hello all i know it is pretty hard one but you will manage it all after noticing and calculating i find a rhythm for the file i want to edit to copy the last 12 characters in line but the problem is to add after first 25 characters in same line in other way too copy the last 12 characters... (10 Replies)
Discussion started by: princesasa
10 Replies

10. Shell Programming and Scripting

Removing uppercase words from textfiles

I have the task of removing all uppercase words from csv files, mit 10000's lines. I think it shoud be possible with regex's, something like "s/{2,}//g" but I can't get it work with sed or Vi. It would also be possible to script in ksh, awk, perl or python. example this "this is a EXAMPLE... (5 Replies)
Discussion started by: frieling
5 Replies
Login or Register to Ask a Question