Extract Only Specific Part From A File

Hello All,

I would like to know if there is a better way to achieve the below task:

Task: Copy lines 10 to 50 from a files that contains 100 lines.

My approach:
1st) use head command and then list first 50 lines and then tail last 40 lines.

2nd) Do a while loop with a counter and then when counter reaches to 10 start writing it to another file up to the point where the counter is 50 and then exit.

I would like to know if there are any other simple and straight approach using which I can directly copy lines 10 to 50.

Help and suggestions on this question are greatly appreciated.

Thanks.


Similar Content



Strip Last Lines Off Pipe

I have a datastream going through a pipe,and I need to strip-out (remove) the last 3 lines (trailer) from that stream so that it doesn't go down to the next command in the stream.
ive tried combinations of head/tail, but that all assumes you know ahead of time how many lines are in the stream to begin with...

Extract Middle Of File - How To Strip Header/footer

I have a log file with a header (which I can skip with awk), and a footer, which I need to find a way to remove. The goal is to extract the middle lines from a file. Specifically, there is a header (1 line) and a footer (1 line).
The only way I can figure out how to do this is if I already know how many lines are in the file to begin with. For example, if the file looks like this: line 1 (header)
line 2 (interesting line)
line 3 (interesting line)
line 4 (footer)
I just want to extract the middle "interesting lines" without the header/footer lines.
I can't use grep to remove the header/footer, because I don't know what those lines will contain, only that they exist and are exactly 1 line each. In general, I don't know how many lines are in the file.

Remove Lines That Are Subsets Of Other Lines In File

Hello everyone,


Although it seems easy, I've been stuck with this problem for a moment now and I can't figure out a way to get it done.

My problem is the following:

I have a file where each line is a sequence of IP addresses, example :

Line 1: 10.0.01 10.0.0.2
Line 2 : 10.0.0.5 10.0.0.1 10.0.0.2
...

What I'd like to do, is to remove lines that are completely matched in other lines. In the previous example, "Line 1" would be deleted as it is contained in "Line 2".

So far, I've worked with python and set() objects to get the job done but I've got more than 100K lines and sets lookups are becoming time consuming as the program goes :/

Thanks for you help

How To Color Different Lines In Gnuplot

Hi there. My environment is Ubuntu 12.04 OS. I have an example of the files I create with gfortran and gnuplot. The gnuplot draws this picture from a data file with 2D Cartesian coordinates. It is perpective projection. I need to color some parts of the plot (various lines) in different colors because some other details must also be drawn and I feel that the resulting network will be confusing. Gnuplot user manuals treat this subject but only in conjunction with lines drawn through a formula like sin(x), etc. I don't have that. All I have is columns of floating point numbers. Is there way I can draw lines of different color with gnuplot 4.6?

Thanks, - A.

WD MyCloud

I'm new to Linux but have a WD MyCloud 2TB NAS. I want to run Logitech Media Server (LMS) on it and have found instructions on Logitech Forums on how to do it. Unfortunately it does not work for me. I've downloaded the deb file and used dpkg -i on that file. This gives a load of lines like this
dpkg: warning: files list file for package 'libpam-winbind:armhf' missing; assuming package has no files currently installed
and in the end LS does not appear to be running. Would anyone know what these lines are telling me and any suggestions as to how to fix the problem.
I can get no response from the Logitech forums so any help here would be greatly appreciated.
PS:The version of Linux seems to be
Linux WDMyCloud 3.2.26 #1 SMP Tue Jun 17 15:53:22 PDT 2014 wd-2.2-rel armv7l

Redirection. Help Pls.

Hello there. Im stuck on a task.

it`s the task:
Search the file 'data' for all of the lines that contain the pattern 'linux'
and put those lines in the file 'matches'.

You entered: grep "linux" date > matches
Please try again.

I tried lots of variants
1) grep linux date > matches
2) grep 'linux' date > matches
3) grep linux date >> matches

May be something`s wrong with grep command?
I just dont get it >.>; it should work fine. Where is my mistake folks?

Script While Loop

Hello,
I'm working on a shell script that needs to read the a file (file1) a batch (read 2000 lines at a time) and then write those lines to seperate file which I'm using to run ldapmodify command. I need to check some other file size and once this file less than 200kb, i would need to run second batch and so on until file1 is empty.
Quote:
#!/bin/bash
set -x
filesize=200
server=10.11.xxx.xx
filename=fileimport.txt
taofile1=687686.txt
taofile=/var/opt/$taofile1

stty -echo
echo -n "Enter password: "
read passwd
stty echo
context="cn=user1,ou=org1,ou=org2,o=org"
if [[ -s "$filename" ]];then
for lines in $filename
do
head -99997 fileimport.txt >> ldapreadd.ldif && sed -i '1,+99996d' fileimport.txt
if [ -s ldapreadd.ldif ];then
ldapmodify -h $server -p 389 -D $context -w $passwd -v -x -f ldapreadd.ldif &> /dev/null
echo "LDIF script is running. Please wait..."
sleep 60
if [ -f "$taofile" ];then
taofilesize=`stat -c %s ${taofile}`
# if [ "$taofilesize" -ge 200 ];then
while [ `stat -c %s ${taofile}` -ge 200 ]
do
echo " Driver is processing LDIF file. Please wait..."
sleep 60
done
fi
rm -rf ldapreadd.ldif
fi
done
else
echo "$filename file is empty. Exiting script..."
exit
fi

I have 2 issues here. first one script is not reading exact lines as specified. Some times its reading more lines some times less lines. Second issues once it run the first batch, script is exiting. Please advise.

Linux Append Lines In A File After Matched Lines Are Found

I want to append lines after a match in a file.

##file name is ssl.conf
##match is this

<Directory "/var/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>

after above line i need to append these lines

<Directory "/">
SSLRenegBufferSize 26215000
</Directory>

so final results should be like this

<Directory "/var/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>

<Directory "/">
SSLRenegBufferSize 26215000
</Directory>

######Thank You in Advance

What Do I Do With This Huge Data On My Command Line Interface

Hi,

I have been trying to get information on how to process the output of a tcl file (aodv and leach protocol using mannasim) which I got on my command line Iinterface. Actually, I don't even know the keywords to search as I am new to this and other minor attempts haven't yielded positive results., I know there is usually a trace file but I can't see any. All I see is on my command line.

I also observe that it took the space on the entire screen and I can't copy the output from the start ( I could only copy from node 19 out of 30 nodes) because of the huge number of output lines.

The last thing I havent been able to figure ou is whether temperature is equivalent to energy Iin mannasim as mannasim has only temperature and carbon dioxide?


Thanks

Ls Command Lists Each File On Separate Line

Don't know how but now when I use ls I get list of files and directories on their own lines. I want the default behavior I had before. When I cd into another directory I have default behavior - horizontal list of files and folders.