cut - new line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cut - new line
# 1  
Old 04-15-2005
Question cut - new line

Hello!!


I'm trying to get each line of a file, using cut and new line "\n" inside a script, but everytime I do the command it returns everything, not limited by the new line.
Am I using a wrong format to new line? Is there another way to do it?


cut -d"\n" -f1 < myFile


Thanks in advance!!
Smilie
# 2  
Old 04-15-2005
From the man page -d is a field delimiter... and you are giving it nothing. which means the default is a tab or space.

If your lines are uniform in length, then you can use -c #-# to get a range of characters say, 1-80...

Also, you might have to put in a printf statement to get the \n to print a newline. Or you can revert to my favorite echo ""
# 3  
Old 04-15-2005
Yes..

-d is the delimiter, but why it isn't recognizing the "\n" ?
Unfortunately the lines are not uniform in length..
# 4  
Old 04-15-2005
I suspect it isnt recognized by -d. I doubt you can use a construct like a newline... maybe you can use the Ascii equiv if it is even supported.

Otherwise you will have to get creative like use a quoted double space \" \"

You can use awk where you can chose $0 which will select the whole line if you dont select a delimiter..

awk '{ print $0 \n }' <Myfile


I think the syntax is wrong but close Smilie.


EDIT: I forgot the quotes!!! this works.

awk '{ print $0 "\n" }' < vglist.sh

Last edited by Kelam_Magnus; 04-15-2005 at 02:30 PM..
# 5  
Old 04-15-2005
Hi Kelam_Magnus


I tried the

awk '{ print $0 "\n" }' < myFile

and it still returns all the lines...
Don't know if makes any difference, but myFile is not a sh file...
# 6  
Old 04-15-2005
please post a snippet of your input file and another snippet of what your output should look like ...
# 7  
Old 04-15-2005
Quote:
Originally Posted by alienET
Hello!!


I'm trying to get each line of a file, using cut and new line "\n" inside a script, but everytime I do the command it returns everything, not limited by the new line.
Am I using a wrong format to new line? Is there another way to do it?


cut -d"\n" -f1 < myFile


Thanks in advance!!
Smilie

I think , you are trying to get/cut the first line of the file.
use the following alternatives.

Code:
head -1 file1

Code:
sed -n '1p' file1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cut line up to a string

hi all In my bash script I want to cut a line up to a specific string and keep the rest of it but only up to a ".How can I do that?I imagine something with sed.. Let's say my line is: Jennifer Jones (student) "id:376765748587/7465674775" NewYork and i only want to keep: ... (9 Replies)
Discussion started by: vlm
9 Replies

2. Slackware

How should I cut this line using cut and grep?

not sure how to do it. wan't to delete it using cut and grep ince i would use it in the shell. but how must the command be? grep "64.233.181.103 wwwGoogle.com" /etc/hosts | cut -d the delimeter is just a space. can you help meplease. :D (1 Reply)
Discussion started by: garfish
1 Replies

3. Shell Programming and Scripting

reading line by line and cut

I have a file like name file.txt whose contents are 3 fields separated by colon':' . somewhat like code/OR_R1400_RC4/BM_ATEMP_11.0.1.33:28/01/2010:N code/OR_R1400_RC5/BM_ATEMP_11.0.1.35:28/01/2010:Y code/OR_R1400_RC4/BM_ATEMP_11.0.1.33:29/01/2010:N... (8 Replies)
Discussion started by: gotam
8 Replies

4. Shell Programming and Scripting

How to cut specific line and one line under?

Hi guys, I need to analyze the following alert log file: Beginning log switch checkpoint up to RBA , SCN: 3916025539605 Sat May 1 00:54:52 2010 Thread 1 advanced to log sequence 271423 (LGWR switch) Current log# 1 seq# 271423 mem# 0: /dw/stg_redo01/log_dwstg_g1_m1.log Current log# 1... (7 Replies)
Discussion started by: nir_s
7 Replies

5. Shell Programming and Scripting

cut a string in a textfile line per line

i need to cut the string in a textfile but each line has a specific way of cutting it (different lengths) i have a for loop that gets the string line per line, then each line has to be compared: for x in `cat tmp2.txt`; do if; then echo 'BAC' elif ... (6 Replies)
Discussion started by: izuma
6 Replies

6. Shell Programming and Scripting

To cut a specific line

Hi, I need to remove a specific line from a file.. For eg: From the html codings, I need to find the word "iframe frameborder" and cut it . I tried with find . -type f -exec grep -H 'iframe frameborder' {} \; > <filename> From the output of this result, I need to remove the "iframe... (14 Replies)
Discussion started by: gsiva
14 Replies

7. Shell Programming and Scripting

How can i cut first line of a file

i want to cut first line of a file and use it.It should remove that line from file content.Plz help me (7 Replies)
Discussion started by: arghya_owen
7 Replies

8. Shell Programming and Scripting

cut in line

hi how can i get from Komendant st. house 50 ex. 1 fl. 1000 to > Kome.50.2.1000 Elsestreet house 51 ex. 2 fl. 11 to > Else.51.2.11 ??? (4 Replies)
Discussion started by: Trump
4 Replies

9. UNIX for Dummies Questions & Answers

cut first 4 characters from a line

Please let me know how to cut first four characters from a line in UNIX after grepping the file.. (5 Replies)
Discussion started by: kaushikraman
5 Replies

10. Shell Programming and Scripting

Line cut

Dear all #!/bin/sh for i in `cat test1` do echo $i field1=`$i | cut -d',' -f4` echo $field1 sleep 5 done test1 file has these contents 2007-05-31-0000,0,0,537,538,489,490,0,0,0,0,0,0,46,46 2007-05-31-0001,0,0,552,552,489,489,2,2,0,0,0,0,60,60... (13 Replies)
Discussion started by: Dastard
13 Replies
Login or Register to Ask a Question