Operating System - HP-UX
1829456 Members
1492 Online
109992 Solutions
New Discussion

How to veiw same file diff lines

 
SOLVED
Go to solution
jayachandran.g
Regular Advisor

How to veiw same file diff lines


Hi

I have a file ll.log

say thr is 1000 lines in this file. How i can extract 10 files each for seperate files.

cat,head and tail commbination is capable of doing only one group of lines at a time. is thr a command that can extract mulitple group of lines at the same time.

as if every file is too big it is taking a lot of time with cat head and tail.

Thank You
7 REPLIES 7
Robert-Jan Goossens_1
Honored Contributor
Solution

Re: How to veiw same file diff lines

Hi,

How about using the split command

SYNOPSIS
split [-l line_count] [-a suffix_length] [file [name]]

split [-b n[k|m]] [-a suffix_length] [file [name]]

Regards,
Robert-Jan
Orhan Biyiklioglu
Respected Contributor

Re: How to veiw same file diff lines

split -l 100 file outfile

will create 10 output files with 100 lines from the input file in each.
jayachandran.g
Regular Advisor

Re: How to veiw same file diff lines

Thanks Robert and Orhan

Sorry the lines numbers are differing for first few files it iwll be 10, some times it will be 18 and 47 also. there are 4 combinations 10,28,47,192
Orhan Biyiklioglu
Respected Contributor

Re: How to veiw same file diff lines

You can try using sed to print the selected lines of a file.

sed -n -e '1,5p' file will print only the lines from 1 to 5 and sed -n -e '5,10p' will print from 5 to 10.

You can use this in a shell script to print different portions of the file and than redirect the output to different output files.

Raj D.
Honored Contributor

Re: How to veiw same file diff lines

Hi Jayachandran ,

Try split , it will split the file with 10 file of 100 lines each.

Here it is :

# split -l 100 file1 file2

The output will be named automatically as

file2aa
file2ab
file2ac
file2ad
file2ae
file2af
file2ag
file2ah
file2ai
file2aj
--------------

Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Sandman!
Honored Contributor

Re: How to veiw same file diff lines

The sed command will do exactly what you're looking for as long as you know the FROM and TO line numbers in the input file that need to be extracted into 10 separate files. For example:

# sed '
> 1,10w 1.out
> 10,47w 2.out
> 18,47w 3.out
> 47,192w 4.out
> ' inputfile

cheers!

jayachandran.g
Regular Advisor

Re: How to veiw same file diff lines

Thanks for all your valuble reply by using sed command i have achived my target thank you.