cutting lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cutting lines
# 1  
Old 06-05-2009
Error cutting lines

Dear All,

Is there a way to cut the lines that have been "head"

Here is what i m trying to do Please advice

there is file name dummy.txt

now i am trying to head this file 4 time by using a loop and every time this file is head with different values

e.g in first instance it will be head -1 for second interval it will be head -20 and so on.

these intevaral are random and are been generated by a counter evertime a script is executed counter bounce with a new value and according to that value file will be "head" four times.

Now the issue is, during the first interval if file is "head 5" times (i.e. head -5) output must be saved with a new file extension, and when its executed second time for (head -10) file should start from (6th value to 16th value and not from 1st to 10th) and so on.

please advice from this point..Smilie

Thankz in advanceSmilie
# 2  
Old 06-05-2009
Simple way to do it:

Code:
 
head -10 <file_name> | tail -5

what this peice of code is trying to do is: get top ten lines of the file and print last five of those to STD output. you can keep appropriate counters to iterate the loop. Also redirect to file accordingly.

Smilie
# 3  
Old 06-05-2009
thnkz for the reply.

the values mentioned here are just an example.

May be this can help you out..

here it is what i am trying to to

For e.g a file name dummy.txt contains value 1-10 coloum wise.

now i want to head this file 4 four times but with different interval (random numbers are generating from a counter.. no help needed for this case)

like in first instant file is head 2 times (head -2 <filename> [output will be 1 2]

now for second time when the file is head let say 4 times (i.e head -4 ) than output should be (3 4 5 6) and not (1 2 3 4).

Similarly, for third and fourth time.

May be this will help ya understand in a better way.

Please help

Thankz in advance.
# 4  
Old 06-05-2009
ok, if I get it right try this:

Code:
sed -n '2,6p' <file_name>

this will print lines starting at column 2 to 6.

Substitute 2 & 6 with your loop variables.

let me know if you need more on this.Smilie
# 5  
Old 06-05-2009
thankz a million shubhendu

now please help in one more thing

my files also contains spaces:

1

2

3

4

.
.
.

if want to remove these spaces how can i do this.

as the below mentioned command is also counting spaces.
# 6  
Old 06-05-2009
You welcome.

This code will delete blank lines from the file:

Code:
 
sed '/^ *$/d' <file_name>

you can either PIPE this or redirect this to a tmp file and do next operation accordingly.

cheers.

Smilie
# 7  
Old 06-05-2009
simply awesome bro...

thnkz a million

GOD BLess ya

-----Post Update-----

Dear All,

now m stuck into this

the following command do execute and provide me my desired result

sed -n '2,6p' <file_name>

but now the issue is, if i want that the values are automatically palced in the said file how to do that

like

sed -n '$varaible1,$variable2p' <file_name>

where variable1 and variable2 are the values that will be placed randomly by the script [I have no issue of placing these variable] the only issue is with the command

please help

-----Post Update-----

please help
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Cutting specific columns from lines

I am trying to remove columns 81-97 from a line that can be as long as 114 characters. Because a number of lines might not have under 80 characters, using the cut command following by paste could be a problem. While sed might work, is there some other utility that could do this more easily? ... (9 Replies)
Discussion started by: wbport
9 Replies

2. UNIX for Dummies Questions & Answers

Cutting lines if conditions are met

Hi. I am not sure how to solve this problem and if it is possible to do so with scripting. :wall: Let's say I have this data: A 12345 12360 A 12359 12380 A 12381 12390 A 12400 12450 A 12451 12460 B 23456 23460 B 23470 23480 B 23477 23505 I wan't each line to be compared in this... (5 Replies)
Discussion started by: danieladna
5 Replies

3. Shell Programming and Scripting

Cutting fields from lines with multiple spaces

Please see the following code, between "status" and "OK" exists many spaces, I want to get status OK . how to ignore multi spaces? If tab exists in the spaces, how to ignore it ? Is there other commands can replace cut? $ echo 'drv status OK'| cut... (3 Replies)
Discussion started by: 915086731
3 Replies

4. Shell Programming and Scripting

Cutting specific lines from a file

Hi, I have a file named Mani.txt. The contents are like this cat Mani.txt -------------------------------------------------------- Hi there how r u My Name is Mani Bye ------------------------------------------------------------ I want to cut the first and last lines from the file... (15 Replies)
Discussion started by: pathanjalireddy
15 Replies

5. Shell Programming and Scripting

need help cutting consecutive lines with sed or awk

HI All, I want to cut 5 lines after a pattern using sed or awk. can any one tell me how to do it ? (2 Replies)
Discussion started by: raghin
2 Replies

6. Shell Programming and Scripting

problem cutting

echo $line|cut -d " " -f`$plannedCount`- and this is the output $ ./read.sh ./read.sh: 12: not found JADE TRADER 143W MYPEN 40 HC M X10 28 7 1 0 ./read.sh: 9: not found MYPEN 20 GP X X10 15 2 1 0 ./read.sh: 9: not found MYPEN 40 GP X X10 28 7 1 0 ./read.sh: 9: not found MYPEN 20... (6 Replies)
Discussion started by: finalight
6 Replies

7. UNIX for Dummies Questions & Answers

cutting

Is there any cut or awk function that would allow me to take the last part of a path away and save the list into a file? I wrote: find $HOME -mtime +3 > fileList cat fileList /home/102/s/jn/folder/HW /home/102/s/jn/otherfolder/B.txt /home/102/s/jn/folder4/3dA/w... (1 Reply)
Discussion started by: terms5
1 Replies

8. UNIX for Dummies Questions & Answers

Cutting the top two lines, and also charachters below.

Hey all. I have a file that I am trying to cut information out of. We have a script that shows us all of our Radio Scanners that are being used and I'm writing a script that clears all of the context off of the scanners. The script that runs shows us this information below... |emp_id ... (5 Replies)
Discussion started by: jalge2
5 Replies

9. UNIX for Dummies Questions & Answers

Cutting n consecutive lines from a file...

Hi, I have this problem of separating 10 consecutive lines from a file, say starting from 21 to 30... I have used a filter like this.. head -n 30 myfile | tail -n 10 Is there a simpler way than this? (2 Replies)
Discussion started by: Vishnu
2 Replies

10. UNIX for Dummies Questions & Answers

Cutting lines out using sed I presume.

Happy New Year!!! I'm trying to cut out some text in a data file where I only want the first line and the last line. For example. 1. Colin Was here <<-- Text I want to cut out 2. THIS IS THE TEXT I WANT TO CUT <- CUT THIS OUT 3. OUT BECAUSE IT'S NO GOOD TO ME <- CUT THIS OUT 4. I... (5 Replies)
Discussion started by: cfoxwell
5 Replies
Login or Register to Ask a Question