Cut line from file till the end


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cut line from file till the end
# 1  
Old 06-30-2011
Bug Cut line from file till the end

Hi
I have a 57 line text file and I want to cut first 6 line assigned it to a veriable and again cut next 6 line assigned to same variable till the time file have left 0 line.

Please let me know how I can do in scripting.

Thanks

Sanjay
# 2  
Old 06-30-2011
We want to help you if you have shown that you have put some effort into solving your own problem but not to do your work for you.
# 3  
Old 07-01-2011
hi

my original file /var/tmp/img-bkp1

head -6 /var/tmp/img-bkp1 >/var/tmp/used
grep -v -f /var/tmp/used /var/tmp/img-bkp1 >/var/tmp/unused.1
head -6 /var/tmp/unused.1 >/var/tmp/used
grep -v -f /var/tmp/used /var/tmp/unused.1 >/var/tmp/unused.2
head -6 /var/tmp/unused.2 > /var/tmp/used
grep -v -f /var/tmp/used /var/tmp/unused.2 >/var/tmp/unused.3

and so on

can you please tell me how put in loop so that file have left 0 line
# 4  
Old 07-01-2011
try this..

Code:
 
for i in 1 7 13 19 25 31 37 43 49 55
do
  plus_six=`echo $i + 6 | bc`
   sed '"$i","$plus_six"p' filename >/var/tmp/output$i.txt
done

# 5  
Old 07-01-2011
use split command to split the file

Code:
split -l 6  /var/tmp/img-bkp1

this will create the xx* file names in the same directory

you can read each one like
Code:
for i in xx*
 
do
 
---
done

Please refer to man pages on split also
# 6  
Old 07-01-2011
try this..
Code:
% split -6 input_file; ls -1 x* | awk ' { print $0"_1=`cat "$0"`;" } ' | sh

# 7  
Old 07-01-2011
Quote:
Originally Posted by Sanjay2121
hi

my original file /var/tmp/img-bkp1

head -6 /var/tmp/img-bkp1 >/var/tmp/used
grep -v -f /var/tmp/used /var/tmp/img-bkp1 >/var/tmp/unused.1
head -6 /var/tmp/unused.1 >/var/tmp/used
grep -v -f /var/tmp/used /var/tmp/unused.1 >/var/tmp/unused.2
head -6 /var/tmp/unused.2 > /var/tmp/used
grep -v -f /var/tmp/used /var/tmp/unused.2 >/var/tmp/unused.3

and so on

can you please tell me how put in loop so that file have left 0 line
Could you please tell us more about your final goal ?

a) How does the content of you input file look like ?
b) Why do you need lines 6 per 6 ?
c) What kind of processing do you run on them ?
d) What kind of output do you expect ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX help to print 50 lines after every 3rd occurrence pattern till end of file

I need help with extract/print lines till stop pattern. This needs to happen after every 3rd occurrence of start pattern and continue till end of file. Consider below is an example of the log file. my start pattern will be every 3rd occurrence of ERROR_FILE_NOT_FOUND and stop pattern will be... (5 Replies)
Discussion started by: NSS
5 Replies

2. Shell Programming and Scripting

Pattern match till the end of the file.

I have a file which is like this ……………………………………….. ………………………………… ………………………………… …………………………………… ……………………………………. ……………………………… <<<from_here>>> ……………………………… ………………………………. I want a script which would fetch the data starting from <<<from_here>>> in the file till the end... (2 Replies)
Discussion started by: halfafringe
2 Replies

3. Shell Programming and Scripting

Remove line starting from space till end.

Hi, I have a code tag, from which i have the below snippet: intelrpt.GetCMB_FB type=ODBC> intelrpt.GetCMB_FB type=SYBASE> I want the output like: intelrpt.GetCMB_FB intelrpt.GetCMB_FB That is remove the lines starting from WHITESPACE till end. Please help. I am new to... (7 Replies)
Discussion started by: anupdas
7 Replies

4. Shell Programming and Scripting

Grep from a starting line till the end of the file

Hi Folks, I got to know from this forums on how to grep from a particular line say line 6 awk 'NR==6 {print;exit}' But how do i grep from line 6 till the end of the file or command output. Thanks, (3 Replies)
Discussion started by: Mr. Zer0
3 Replies

5. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

6. Shell Programming and Scripting

Subsitute from a position till end of line.

Hi, Having a following file's content, lets say: ABC|ANA|LDJ|||||DKD|||||| AJJ|KKDD||KKDK|||||||||||| KKD||KD|||LLLD||||LLD||||| Problem: Need to replace pipes from 8th occurrence of pipe till end. so the result should be: ABC|ANA|LDJ|||||DKD AJJ|KKDD||KKDK|||| ------- ------- ... (12 Replies)
Discussion started by: _Noprofi
12 Replies

7. UNIX for Advanced & Expert Users

Urgent Help required : awk/sed help to find pattern and delete till end of line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (1 Reply)
Discussion started by: rajan_san
1 Replies

8. Shell Programming and Scripting

Urgent! Sed/Awk Filter Find Pattern Delete Till End Of Line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (2 Replies)
Discussion started by: rajan_san
2 Replies

9. Shell Programming and Scripting

How to Select or cut from the certain filed to the end of the line

Hi: I have few rows in file..Like suppose... 9063C0 44 00051363603253033253347 3333 070248 06 9063C0 5G PAN00013 9063C0 44 00061030305040404250724 0506 100248 08 9063C0 43 01 00000089 I need to cut the row starting after... (5 Replies)
Discussion started by: grajesh_955
5 Replies

10. Shell Programming and Scripting

To cut end string from line

HI, I want to cut end string from line. e.g. i have following input line /users/home/test.txt I want to get end string 'test.txt' from above line and length of that end string will change and it always start after '/'. Thanks, Visu (7 Replies)
Discussion started by: visu
7 Replies
Login or Register to Ask a Question