how to remove tab space only in the column of a specific row


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
how to remove tab space only in the column of a specific row

Hi,
I need help to remove tab delimited space in the $2 of a specific row. My file is like this:-

file1.txt
Code:
No_1    4    139    156
No_1    5    161    205
No_4    91    227    212
No_19   254    243    263
No_19   645   249    258
No_19   101  2492    2635
No_90   8    277    288

file2.txt
Code:
ID    L_254
NAME    L_254
START    39644
END    37193
LINE    unknown
TYPE    R
N    37736-37861
@@
ID    L_101
NAME   L_101
START    314257
END    312432
LINE    unknown
TYPE    R
@@
ID    L_8
NAME   L_8
START    3196078
END    3194948
LINE    unknown
TYPE    R
@@

i used a script like this to update my file2.txt with values of START and END in file1.txt.

Code:
FNR==NR{b[$2]=$3;f[$2]=$4; OFS="\t"; next}
$1=="ID" {id=substr($2,index($2,"_")+1)}
id in b {$2=($1=="START")?b[id]:(($1=="END")?f[id]:$2)}
1

My output is tab separated. The code above works great for the values update but the problem is after each '@@'. i don't want the column after each '@@" in tab separated. It should be considered as the end of the line. It should be just @@ instead of @@\t. Thanks in advance..
# 2  
Code:
sed 's/^\(your_first_pattern\)TAB\(your_end_pattern\)$/\1\2/' input_file >output_file

TAB is a literal tab, your_first_pattern and your_end_pattern must regular-expressions that define and accept what you want to keep.

Last edited by DGPickett; 09-19-2012 at 06:02 PM..
# 3  
Hi DGpickett,

Thanks for your response. I believe that your code is for one file only. I have thousands of separate files that i need to remove the tab. Is there any other way to do this? thanks
# 4  
As long as the pattern does not change, this is quick and robust:
Code:
 
find /top_directory_path -name your_pattern -type f | while read f
do
  sed ... $f >$f.new
  if [ "$( cmp $f $f.new 2>&1 )" = "" -s -s $f -a -s $f.new ]
  then
    mv $f $f.old
    mv $f.new $f
  else
    rm $f.new
  fi
done

If file names have spaces or metacharacters, put "$f" for $f.
# 5  
Hi,

Can you please explain to me your code? i dont really familiar with sed. i tried your code couple of times but i got infinite loop in my shell.
# 6  
sed is a stream editor, it reads in a loop applying the script to each line read and then writing it. It never uses a temp file or runs out of space on huge data sets when you use it on pipes.

The command s/pattern/new_data/ is a substitute. The pattern is regular expressions (regex) slightly expanded to allow \(\) pickup and \number put back down in the substitute. In your case, the regex can identify lines where the tab must be removed, and where in the line the tab is. For just every @@TAB, you could just scrub that phrase as many times on any line as it appears:
Code:
s/@@TAB/@@/g

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #792
Difficulty: Easy
In mathematics and digital electronics, a binary number is a number expressed in the base-2 numeral system or binary numeral system.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using awk to change a specific column and in a specific row

I am trying to change the number in bold to 2400 01,000300032,193631306,190619,0640,1,80,,2/ 02,193631306,000300032,1,190618,0640,CAD,2/ I'm not sure if sed or awk is the answer. I was going to use sed and do a character count up to that point, but that column directly before 0640 might... (8 Replies)
Discussion started by: juggernautjoee
8 Replies

2. Shell Programming and Scripting

How to remove tab space if any in a variable?

I have a variable sumOfJEOutputFile which is the output file of an SQL command which contains the output of that SQL. The output looks like below: ----------- 58 I am using following code to manipulate the output: (sed 1,2d $sumOfJEOutputFile > $newTemp1 | sed '$d' $newTemp1)... (4 Replies)
Discussion started by: Sharma331
4 Replies

3. Shell Programming and Scripting

How to remove alphabets/special characters/space in the 5th field of a tab delimited file?

Thank you for 4 looking this post. We have a tab delimited file where we are facing problem in a lot of funny character. I have tried using awk but failed that is not working. In the 5th field ID which is supposed to be a integer only of that file, we are getting corrupted data as below. I... (12 Replies)
Discussion started by: Srithar
12 Replies

4. Shell Programming and Scripting

Converting Single Column into Multiple rows, but with strings to specific tab column

Dear fellows, I need your help. I'm trying to write a script to convert a single column into multiple rows. But it need to recognize the beginning of the string and set it to its specific Column number. Each Line (loop) begins with digit (RANGE). At this moment it's kind of working, but it... (6 Replies)
Discussion started by: AK47
6 Replies

5. UNIX for Dummies Questions & Answers

awk: convert column to row in a specific way

Hi all! I have this kind of output: a1|b1|c1|d1|e1 a2|b2|c2 a3|b3|c3|d3 I would like to transpose columns d and e (when they exist) in column c, and under the row where they come from. Then copying the beginning of the row. In order to obtain: a1|b1|c1 a1|b1|d1 a1|b1|e1 a2|b2|c2... (1 Reply)
Discussion started by: lucasvs
1 Replies

6. Shell Programming and Scripting

awk - remove row if specific field is empty/blank

I have this text.filecharles darwin sam delight george washington johnson culper darwin sam delight micheal jackson penny lite and would like to remove the row, if the first field is blank. so the result would be: result.filecharles darwin sam ... (4 Replies)
Discussion started by: charles33
4 Replies

7. Shell Programming and Scripting

delete a row with a specific value at a certain column

Hi, I want to delete rows that have 0 at column 4. The file looks like this: chr01 13 61 2 chr01 65 153 0 chr01 157 309 1 chr01 313 309 0 chr01 317 469 1 chr01 473 557 0 I want to delete all rows with a 0 at column 4 chr01 13 61 2 chr01 157 309 1 chr01 ... (3 Replies)
Discussion started by: kylle345
3 Replies

8. Shell Programming and Scripting

How to remove tab space and new line from a file using sed?

i am using the default sed package that comes with solaris. (11 Replies)
Discussion started by: chidori
11 Replies

9. Shell Programming and Scripting

how to display column value in a row with space as delimeter

Hi I need to write a small script to kill the process id of particular job in one shot , Example > ps PID TTY TIME COMMAND 16280 pts/70 0:00 sh 16278 pts/70 0:00 rlogind 16197 pts/70 0:00 ps 1234 pts/70 0:00 runflow 2341 pts/70 0:00 runflow 12673 pts/70 ... (6 Replies)
Discussion started by: mani_isha
6 Replies

10. Shell Programming and Scripting

Insert a text from a specific row into a specific column using SED or AWK

Hi, I am having trouble converting a text file. I have been working for this whole day now, still i couldn't make it. Here is how the text file looks: _______________________________________________________ DEVICE STATUS INFORMATION FOR LOCATION 1: OPER STATES: Disabled E:Enabled ... (5 Replies)
Discussion started by: Issemael
5 Replies

Featured Tech Videos