emulating cat in sed with q option


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers emulating cat in sed with q option
# 1  
Old 12-28-2011
emulating cat in sed with q option

Hi,

I am aware that the below are the equivalent in sed for cat command.
Code:
sed ':'
sed -n 'p'

Is there any way to emulate the same using "q" option in sed?

Thanks
# 2  
Old 12-28-2011
Assuming that there are less than 100,000 lines in your file:

Code:
sed '100000q' filename.txt

# 3  
Old 12-28-2011
Yes. But the thing is we don't know the number of lines in the file. It may be dynamic.
Is there any one liner available using "q" in this case?
We can do it after finding wc -l , then using "q" in sed.
But is there any other smarter way?
Thanks
# 4  
Old 12-28-2011
The smart way is to not use 'sed'.

Any real world reason for this question?
# 5  
Old 12-28-2011
No reason.Just wanted to know , is there any trick for achieving this.

Thanks
# 6  
Old 12-28-2011
Try this:-
Code:
alias sed=cat

Of course this means you can't use anything else in sed but then if you want to use the wrong tool to replace cat, then this must be suitable.......


As it is Christmas
Code:
cat "food in tins"

Smilie



Robin
# 7  
Old 12-28-2011
Good!Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to cat via ssh and sed at the same time.?

I am trying to write a script to automatically create conf files and remote servers. I would like to do all this without creating files locally and copying them . Here is what I have tried. sitename=$1 prodserver=$2 ssh $prodserver "cat > /data/$sitename.conf" << cat |sed... (5 Replies)
Discussion started by: macrossm
5 Replies

2. Shell Programming and Scripting

sed -n option

Hi i am facing problem with sed -n option could you please help me on this, i have a file test the contents of the file is width="75">10/0 4/12</td>^M><a href='courtorders/100412zr.pdf' target="_blank">Miscellaneous Order</a></td>^M width="75">10/01/12</td>^M><a href='courtorde... (8 Replies)
Discussion started by: ragilla
8 Replies

3. Shell Programming and Scripting

sed with -e option

sed "s/^/8,A1,$dat,id2_3,/g" -e sed "s/$/,,,,,,,,,,,/g" temporary wn m running this script m getting a error... plz help me with this.... O/p sed: -e expression #1, char 3: unterminated `s' command ---------- Post updated at 11:35 AM ---------- Previous update was at 11:33 AM... (7 Replies)
Discussion started by: nikhil jain
7 Replies

4. Shell Programming and Scripting

sed 'b' option

Hi, What does the following command do on files? sed '1b; $d' To me it just deletes the last line of the file. If so what is the significance of sed's 'b' option? Thanks (1 Reply)
Discussion started by: royalibrahim
1 Replies

5. UNIX for Dummies Questions & Answers

sed -i option example

Can anyone give detailed and example for sed -i option. Where can we use this option?:) (3 Replies)
Discussion started by: gwgreen1
3 Replies

6. Shell Programming and Scripting

grep or cat using sed

Is there a way using grep or cat a file to create a new file based on whether the first 9 positions of each record is less than 399999999? This is a fixed file format. (3 Replies)
Discussion started by: ski
3 Replies

7. Shell Programming and Scripting

want to pass sentence with SED and CAT

I have to pass a sentence in a file, the specs are as: cat run | sed 's/SRT/'$8'/g' | sed 's/plength/68/g' | sed 's/stcol/'$5'/g' | sed 's/encol/'$6'/g' | sed 's/brdtype/'$1'/g' | sed 's/brdtxt/'$3'/g' | sed 's/demotxt/Total '$2'/g' | sed 's/bantxt/ban_'$7'/g' | sed 's/validcodes/'$4'/g' > runx... (1 Reply)
Discussion started by: patilrakesh1984
1 Replies

8. Shell Programming and Scripting

Help on cat with sed!

Hi All! I have a script having one statement like. cat xfile | sed 's/A/a/g' > xfile I have two boxes which have similar version of linux running but one is greater in speed compared to other. Lets say A is faster than B. A which is faster writes output as NULL B which... (6 Replies)
Discussion started by: kbalaji_uk
6 Replies

9. UNIX for Dummies Questions & Answers

tr, sed, awk, cat or scripting

I need to change all Newline caracters (\12) to Fieldseparator(\34). tr -A '\12' '\34' <file1> file2 Replace all delete (\177) with Newline (\12) tr -A '\177' '\12' <file2> file3 Put the name of the file first in all rows. awk '{printf "%s\34%s\n", FILENAME,$0} file3 > file4 So far no... (6 Replies)
Discussion started by: MrKlint
6 Replies

10. UNIX for Advanced & Expert Users

use of sed over cat to merge files

I have three files, basically: file 1 - one line header file 2 - big data (approx 80GB) file 3 - a one line trailer the existing process cats these together i.e cat file 1 file 2 file 3 however... I was thinking, surely it could be more efficient to insert the header (file 1) on the... (2 Replies)
Discussion started by: miwinter
2 Replies
Login or Register to Ask a Question