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...


Similar Content



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.

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

Configuring Ns-2.35 And Sumo For TraNS In Fedora 15

hello
i installed sumo-0.9.8 and ns-2.35 in fedora 15. i want to use TraNS.
i know that TraNS no need to install. but it needs to be configured for using ns-2.
when i use the command patch -p0 < traci.patch
the error is appeared
Quote:
[root@Fedora-15 ns-allinone-2.35]# patch -p0 < traci.patch
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|*** Makefile.in.2.29 2005-10-20 06:45:22.000000000 +0200
|--- Makefile.in 2007-09-11 13:46:57.000000000 +0200
--------------------------
File to patch: traci.patch
patching file traci.patch
Hunk #1 FAILED at 85.
Hunk #2 succeeded at 90 with fuzz 2 (offset -1 lines).
Hunk #3 succeeded at 152 with fuzz 2 (offset -2 lines).
Hunk #4 succeeded at 318 with fuzz 2 (offset -3 lines).
Hunk #5 FAILED at 345.
2 out of 5 hunks FAILED -- saving rejects to file traci.patch.rej
can't find file to patch at input line 74
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|*** common/mobilenode.h.2.31 2007-09-20 13:13:18.000000000 +0200
|--- common/mobilenode.h 2007-09-20 13:13:59.000000000 +0200
--------------------------
and when i use the command patch traci.patch
it needs too time to patch .(the traci.patch is 3kB).
what's the matter?

thanks

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.

Write To Pipe File Hangs (using Echo Command)

HI,

I am a newbie to Linux and am trying to create a pipe file with the below command:

mkfifo pone

Now I am trying to write data to the file with the following command on the command prompt:

echo asdadsasdasdasdasdasd >./pone

But after i enter this command- the screen hangs up and doesnt proceed ahead.
Same thing happened when I tried writing using:
gedit pone


Can anyone help me resolve this issue?

Quick GREP Question..

Hey guys,

Something is puzzling me!

I saw someone use the grep in the following way and I'm not sure I understand what it does, and if there's any benefit to using it this way.

Code:
grep X.X.X.X /var/log/log.log | grep -v query

I checked the man file which confirmed that -v is relating to matching non grouping lines (which I'm not sure I fully understand either!) but I don't see any difference in the output of the above command versus the same command without the | grep -v query bit..

Why would you pipe grep into grep unless you were searching for something specific within the search results?

Does query mean something else?

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.

Broken Pipe

yesterday i hasd my network working perfectly. i switched it on today and the synology disk station wont display the contents. i can see the synology drive icon and i have the network set to automatic but it says there is a broken pipe? what the hell is a broken pipe? like for stoners or crackheads? theres nothing wrong with my crack pipe but i guess theres soenthing else i dont know here?

any suggestions guys?

Inet.conf Never Start The Ftp Daemon

Hi,

i am trying the run a ftp daemon on my board (sbc6000x) but it seems that the ftpd service is never started by inetd.conf.

My inetd.conf is :

Code:
#<service_name>	<sock_type>	<proto>	<flags> <user> 	<server_path> 	<args> 

ftp			stream		tcp		nowait	root	/usr/bin/ftpd ftpd -w
telnet			stream		tcp		nowait	root    /usr/sbin/telnetd

Telnet don't run too but this is because i am missing some folders and i can launch it manually after creating the folders without issue, but maybe the fact that it can't run telnet because of the missing folders make it stop trying the ftp daemon ?

I check with the command "ps", the processus is not running hidden anywhere.