I have a big file with many lines and a first line that has something like 100 000 characters.
I'm trying to keep the first 52000 characters from the first line and only the first line In Addtion to the rest of the file, which remains the same.
I've search for the net but I only found solutions where the removal of the first n-th characters was the norm.
I thought about cut -c 1-52000
but cut
will remove every line and I want only the first line to keep up to 52000 characters.
I checked on sed
but I did not find something useful.
I thought about this one
awk '{ NR==1 substr( 1, 52000) } { print }' infile
Do you think it would work?
Any tips are welcomed.
What about this:
dd if=yourfile bs=52000 count=1 2>/dev/null | head -n 1
If you're certain that the first line contains more than 52000 characters, you could use head
. Saying:
head -c 52000 filename
would produce the first 52000 bytes from the specified file (note that the specified bytes aren't restricted to the first line).
From man head
:
-c, --bytes=[-]K
print the first K bytes of each file; with the leading `-',
print all but the last K bytes of each file
Using head
a variant that would produce the desired result (only from the first line) would be:
head -1 filename | head -c 52000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With