Skip to content
Advertisement

Redirect file in linux using length [closed]

Am trying to redirect the file based on the length. I have a file having the value, I like Linux I have to create a new file base on length, 0-6 will provide me I like.

In case of line number we can redirect using,

head-100 file_name.txt > file_name_new.txt

Not sure how to redirect using length of the data. Any suggestion will be helpful

Advertisement

Answer

When you say “length of data”, do you mean number of characters of each line? If so you can use cut command:

head -n100 file_name.txt | cut -c 1-10 > file_name_new.txt

Where [1-10] is the range of the characters you want to keep.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement