Visit Our UNIX and Linux User Community


SED + "tab" character


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers SED + "tab" character
# 1  
Old 11-09-2009
SED + "tab" character

hi all,

i would like your help with the "sed" command

GIVEN a file with the following format, let s say :
Code:
In the house, there are
	no.PCs	3

WHAT i would like to do is to replace the value "3" with another number

IF i type the sed command like this :
Code:
sed 's/'no.PCs[^t]3'/'no.PCs[^t]1'/g' [ooops] > [ooops].temp

i manage to change the value of "3" to "1"
BUT i am not able to insert a "tab" between the "no.PCs" and "1"
and i do not know why Smilie

i would be thankful for any useful comments

PS. i have attached the "[ooops]" file that describes the format i mentioned earlier
# 2  
Old 11-09-2009
Try:
Code:
sed 's/no\.PCs\t3/no.PCs\t1/g'

# 3  
Old 11-09-2009
Code:
awk  '/no\.PC/{gsub($NF,"1")}1' file

# 4  
Old 11-09-2009
thank you for your interest, at first.

@Scrutinizer : doesn t seem to do the right thing
@ghostdog74 : does the right thing BUT could you help me by explaining :
1. what is the purpose of the last --->1<--- in :
Code:
awk  '/no\.PC/{gsub($NF,"1")}1' file

2. when i execute this command, the output file now includes the following :
Code:
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf110
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\paperw11900\paperh16840\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural

\f0\fs24 \cf0 In the house, there are\
	no.PCs	1

is there any idea how NOT to include all this metadata information ?

thank you again
# 5  
Old 11-09-2009
the "1" is just short form to print. you can write this way
Code:
awk  '/no\.PC/{gsub($NF,"1")}{print}' file

when you posted your sample, you didn't include those metadata. next time, give as much information as close to your actual input as possible. So , again, what's really your final output?
# 6  
Old 11-09-2009
Quote:
Originally Posted by OneDreamCloser
thank you for your interest, at first.

@Scrutinizer : doesn t seem to do the right thing
On my system it does this:
Code:
$> sed 's/no\.PCs\t3/no.PCs\t1/g' infile
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf110
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\paperw11900\paperh16840\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural

\f0\fs24 \cf0 In the house, there are\
        no.PCs  1}

Perhaps your sed is '\t' challenged..
# 7  
Old 11-09-2009
the input file contains only this text :
Code:
In the house, there are
	no.PCs	3

but, when i execute :
Code:
awk  '/no\.PC/{gsub($NF,"1")}{print}' [ooops] > [ooops].temp

the output file contains this text :
Code:
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf110
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\paperw11900\paperh16840\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural

\f0\fs24 \cf0 In the house, there are\
	no.PCs	1


U P D A T E :
ok, if i create the file using the touch command, everything works just fine
thank you all for helping me

Last edited by OneDreamCloser; 11-09-2009 at 10:49 AM..
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #268
Difficulty: Easy
In 1936, Turing published his paper 'On Computable Numbers, with an Application to the Entscheidungsproblem'. In this paper, Turing reformulated Kurt Godel's 1931 results on the limits of proof and computation, replacing Godel's universal arithmetic-based formal language with the formal and simple hypothetical devices that became known as Turing machines.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed random \n for "n" range of character occurrences

I'd like to put paragraph breaks \n\n randomly between 5 - 10 occurrences of the dot character (.), for an entire text file. How to do that? In other words, anywhere between every 5 -10 sentences, a new paragraph will generate. There are no other uses of the (.) except for sentence breaks in... (11 Replies)
Discussion started by: p1ne
11 Replies

2. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

3. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

4. Shell Programming and Scripting

sed escape character for comment string "/*"

Good afternoon all, I'm hoping my newbie question can help bolster someone's street_cred.sh today. I'm trying to "fingerprint" SQL on its way into the rdbms for a benchmarking process (so I can tie the resource allocation back to the process more precisely). To do this, I'm essentially... (4 Replies)
Discussion started by: toeharp
4 Replies

5. Shell Programming and Scripting

How to print range of lines using sed when pattern has special character "["

Hi, My input has much more lines, but few of them are below pin(IDF) { direction : input; drc_pinsigtype : signal; pin(SELDIV6) { direction : input; drc_pinsigtype : ... (3 Replies)
Discussion started by: nehashine
3 Replies

6. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

7. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

8. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

9. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

10. Shell Programming and Scripting

removing the "\" and "\n" character using sed or tr

Hi All, I'm trying to write a ksh script to parse a file. When the "\" character is encountered, it should be removed and the next line should be concatenated with the current line. For example... this is a test line #1\ should be concatenated with line #2\ and line number 3 when this... (3 Replies)
Discussion started by: newbie_coder
3 Replies

Featured Tech Videos