The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Cutting specific lines from a file pathanjalireddy Shell Programming and Scripting 15 06-04-2009 01:32 AM
need help cutting consecutive lines with sed or awk raghin Shell Programming and Scripting 2 06-04-2008 04:59 AM
Cutting the top two lines, and also charachters below. jalge2 UNIX for Dummies Questions & Answers 5 08-02-2005 02:59 PM
Cutting n consecutive lines from a file... Vishnu UNIX for Dummies Questions & Answers 2 10-18-2002 10:49 AM
Cutting lines out using sed I presume. cfoxwell UNIX for Dummies Questions & Answers 5 01-08-2002 12:13 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-05-2009
jojo123 jojo123 is offline
Registered User
  
 

Join Date: May 2009
Posts: 51
Exclamation 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..

Thankz in advance
  #2 (permalink)  
Old 06-05-2009
shubhendu shubhendu is offline
Registered User
  
 

Join Date: May 2009
Location: 12° 58' N & 77° 38' E
Posts: 29
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.

  #3 (permalink)  
Old 06-05-2009
jojo123 jojo123 is offline
Registered User
  
 

Join Date: May 2009
Posts: 51
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 (permalink)  
Old 06-05-2009
shubhendu shubhendu is offline
Registered User
  
 

Join Date: May 2009
Location: 12° 58' N & 77° 38' E
Posts: 29
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.
  #5 (permalink)  
Old 06-05-2009
jojo123 jojo123 is offline
Registered User
  
 

Join Date: May 2009
Posts: 51
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 (permalink)  
Old 06-05-2009
shubhendu shubhendu is offline
Registered User
  
 

Join Date: May 2009
Location: 12° 58' N & 77° 38' E
Posts: 29
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.

  #7 (permalink)  
Old 06-05-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
use DOUBLE quotes.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0