General :: Sed - Print Line Number Along With The Line?
Jan 30, 2011
I want to print the line number with the pattern of the line on a same line using multi-patterns in sed. But i don't know how to do it. For example, I have a file
abc
def
ghi
I want to print
1 abc
2 def
3 ghi
View 6 Replies
ADVERTISEMENT
Feb 8, 2010
After running the following command, I get:
[root@yukiko /]# find / -iname .bashrc
/home/clamav/.bashrc
/home/vpopmail/.bashrc
/etc/skel/.bashrc
/root/.bashrc
But I would like to have a command that prints a specific line by supplying the command with the line number, for example:
[root@yukiko /]# find / -iname .bashrc | getline(2)
/home/vpopmail/.bashrc
Is there such a command on CentOS?
View 3 Replies
View Related
Jul 25, 2011
I want to insert a line at a particular line number using sed or awk. where line number is not fixed and is in form of variable.
I want to use variable in sed or awk command.I tried something like below, but no luck.
View 7 Replies
View Related
Jan 8, 2010
I want to sort a number of lines based on their size:
data:
-------
12345678
87654321
1234
[code]....
Should output as:
-----------------
1
2
12
21
[code]....
But i'm gettings this with sort
----------------
1
12
123
1234
[code]....
Can we sort the above "data" text, based on "number of characters" instead of "character order"?
View 8 Replies
View Related
Aug 2, 2010
I've written a script to parse a file and print each line that ends with matching pattern, if the next line is blank. The pattern lines are the result of md5sum $i|sed 's/path///g' so that only md5 and filename appear. Here's what I'm using.
Quote:
for fline in `sed -n '/.*.ext$/p' file1`
do
if [ "`sed -n -e '/'"$fline"'/ {n; p;}' file1`" == "" ]
then
echo ""$fline" has no info" >>file2
fi
done
[Code]....
View 4 Replies
View Related
May 30, 2011
I am trying to write a program in C which compares two files and prints the line that is equal.
Here file1.txt has
and file2.txt has
Note: file2.txt consist of only a single string where as file2.txt has multiple lines. Actually im comparing two files with md5sum values.
Here is the code but it compares only first line of files..but it should compare the whole file1..and sorry iam a beginner in C can any1 sujest some modification to this code so that..it can compare file2 with entire file1
Quote:
View 9 Replies
View Related
Jun 15, 2010
I m writing a script to delete a line at particular location.
But i m unable to use variable for specifying line number.
For example.
Code:
works fine and deletes 7th line from my file
But
Code:
gives following error.
Code:
View 7 Replies
View Related
Apr 11, 2010
I have a project due for my Intro to C++ class and we are suppose to generate a file listing that will take an input of a C++ source code with .cpp extension and make a copy of it with a .lst extention that will have a line number preceding each and every line.
View 12 Replies
View Related
May 21, 2010
I have a perl/python interpreter available on the system so really as long as the script would run on a standard linux build I'll be happy.So I don't know how to program a script that would find the unique key (which if needed, can be easily stripped out and put into a separate file) and then print out the data below it without going into the other lines.
View 4 Replies
View Related
Jul 5, 2011
I'm trying to use sed to search for a certain 'primary' pattern that may exist on several lines, with each primary pattern followed by an --unknown-- number of 'secondary' patterns.The lines containing the pattern start with: test(header_name)On that same line is an arbitrary number of strings that come after it.I want to move those strings over to their own lines so that they each are preceded by their own test(header_name).e.g. Original file (mytest.txt):
apples
test("Type1", "hat", "cat", "dog", "house");
bananas
[code]....
View 2 Replies
View Related
Dec 6, 2010
I am using Vi editor for editing and configuring my file.I am facing a little problem when there is long file like 3000 lines. Normally i use
Code:
:set number
in vi editor to visible my line number.The problem is when i have to go in the top of the file like say line number one I use k for it and to move down I use j which is too much time consuming. How can i jump directly my cursor to line number 2333 or line number 2600.
View 4 Replies
View Related
Jul 20, 2010
I have a big file full of records like this
1, 2, 4, 5, 6
1, 3, 5, 6, 3
1, 4, 5, 6, 6
2, 4, 5, 5, 5
2, 3, 4, 5, 2
anyway i need to take the average of all rows with the same 1st number(key). i.e.
1, 3, 4.66, 5.66, 5
2, 3.5, 4.5, 5, 3.5
I know this is something awk/sed would be great for, i just dont have enough experience with them to accomplish it, Also, what about averaging those columns together? so, after I output this to a file, id like to get another like:
1, 4.58
1, 4.125
The number of colums to add might not always be 4 either. EDIT: this might be easier to do in gnuplot, so I mainly just need an answer to the first part.
View 3 Replies
View Related
Jul 22, 2010
I'm not that familiar with sed and awk in order to be able to solve this problem on my own, so I'm calling on you for a bit of assistance. I'm writing a Nagios plugin to check our Oracle tablespaces and the output is given in one line like this: 1.04007771 TEMP 0 UNDOTBS1 .005340579 USERS 0 7 rows selected. I've been playing around with sed like below to delete the obsolete info and change every second space into a newline:
[code]...
how many tablespaces there are so I'd have to check all databases and 'hardcode' the tablespaces in my script. Is there any way to 'automate' this knowing that 'rows selected' preceded by a number is always the last line and using a sort of counter to auto-adjust the number to put in the -e 's/ / /2' part?
View 7 Replies
View Related
Mar 22, 2011
I have two files, file1.traj and file2.traj. Both these files contain identical data and the data are arranged in same format in them. The first line of both files is a comment.
At line 7843 of both files there is a cartesian coordinate X, Y and Z ( three digits ). And at line 15685 there is another three digits. The number of lines in between two cartesian coordinates are 7841. And there are few hundreds of thousands of lines in a file.
What I need to do is copy the X Y Z coordinate (three digits) from file1.traj at line 7843 and paste into file2.traj at the same line number as in file1.traj. The next line will be 15685 from file1.traj and replace at line 15685 at file2.traj. And I dont want other lines (data) in file2.traj get altered. This sequence shall be going on until the end of the file. Means copy and substitude the selected lines from file1.traj into file2.traj.
I tried to use paste command but I cant do for specified line alone.
Here i showed the data format in the file. I used the line number for clarity purpose.
Code:
View 10 Replies
View Related
Apr 9, 2010
I need to organise an external HDD such that there is no more than 500 folders on it.
Ubuntu's "Properties" pane shows only the file count, not the folder count.
Is there a simple CLI line that will tell me the number of subdirectories?
View 3 Replies
View Related
Dec 21, 2010
How to print a sequence of line say line number 10 to 20 of a 50 line file ?
View 6 Replies
View Related
Feb 13, 2011
I want to access a file, and check the length of every line.After, i want to check and replace all lines with length over 10 characters, with a message.Does anyone have a clue on that?
View 1 Replies
View Related
Jul 12, 2010
I read this thread but
Code:
anisha@linux-uitj:~> su
Password:
[code]...
View 14 Replies
View Related
Sep 22, 2011
I'd like to print only few groups from text matching a regex. How can I do that in the Linux command line?
What other tools for text processing are there in Linux?
View 3 Replies
View Related
Apr 3, 2011
CUPS was not originally installed on my server, I have installed it but cannot print to my network printer. On my laptop, I can... they are both running the same version of Debian. What could be missing?
Here are some details...
I have two computers running the same version of Debian. One is a server with no GUI and the other is my laptop with GDM installed. My laptop (which prints with no problem) is connected via Wifi. My server is connected directly to the router via Ethernet. I cannot print from the server.
The printer is a Canon Pixma MP495 that connects to the router via Wifi. I have downloaded drivers for the printer from [url] and installed them successfully using dpkg on both computers.
Right now I have a regular text file that I am using for a test page. To print from my laptop (with success) I type:
Code:
This does not work from the server. What could I be missing?
lpq run on server:
Code:
lpinfo readout:
Code:
View 14 Replies
View Related
Oct 7, 2010
How to create cron tab when DSL line down set automatically restart the network service while DSL line up?
View 3 Replies
View Related
Sep 11, 2009
I have several files with many lines something like this:
I'm trying to write a script that will count the number of characters per line that doesn't contain a ">" symbol and give me an average of those values. I have most of the script together but I can't figure out how to connect some of the steps.
Code:
View 3 Replies
View Related
Dec 23, 2009
I am trying to write a script that takes an input file ($FileName) and an intermediate file ($FileName.info) and removes lines from $FileName if the value in $2 of $FileName.info is <75.
I can't figure out how to feed only one line of the .info file to the if statement at a time so that it will perceive it as an integer instead of a list.
The error I am getting now is ./script.sh: line 6: [: : integer expression expected
Sample input $FileName
Code:
Code:
Code:
Script so far:
Code:
View 10 Replies
View Related
Feb 24, 2011
I'd like show a certain line or lines of a file with context, kind of like a unified diff, on the command line in Linux:
$ (something) -l 154 stuff.py
150: def foo(bar):
151: """
[code]....
View 5 Replies
View Related
Aug 22, 2011
How can I print Linux command line history without including the line numbers? I want to send it all to a text file like this:history >> history.txt
View 1 Replies
View Related
Apr 1, 2011
I am combining data from a couple different input files and creating an output file in a specific format. I notice that if I use the >> operator, information gets appended to a new line in my output file. This is useful, but if I'd like to append onto the CURRENT line, is there an easy way to do this? I've been googling around and see lots of complicated answers, nothing that suggests to me an easy way to do this. For example, if my output file looks like this:
b1a:] cat test
hello my name is
b1a:]
and I'd simply like to append "Bob", how can I do it? If I use
b1a:] echo Bob >> test
b1a:] cat test
b1a:] hello my name is
Bob
b1a:]
So what I would prefer is some command that would create the result:
hello my name is Bob
View 14 Replies
View Related
Mar 21, 2011
This solution works but is slow with large files. I am looking for a faster solution.
The 2 files contain filenames, one of them has associated data I want to append to the other file's matching filenames
file1:
file2:
I append file2 by matching the unique_filenames and appending them with the tag data and some formatting
appended file2:
Here is the SLOW code
while read inputline.
View 9 Replies
View Related
Mar 30, 2011
I need to grep for a particular string and if found need to display the line containing that string, the line above that and also the first line of that paragraph.
Can this be done via sed.
Eg, My Paragraphs
OA connectA
Enclosure:
Interconnect Module #6 Status:
Here, if I grep for Critical, it should display the following
Similarly if I grep for Degraded, it should display
View 3 Replies
View Related
May 13, 2010
I have to do several scripts and I have no idea of how to do this one: Make a script that read line by line the passwd file and prints in console.Hope you understand couse my english isso bad as you can see.Our teacher told us something like this:#!/bin/bashwhile read line doecho $lineadone < dispositiveexit
View 9 Replies
View Related
Sep 1, 2009
I have a dataset (see example below) that I would like to go through and copy all lines containing a certain string ("LGIG") plus the line immediately following that line to a new file. I have no problem grepping lines containing the string LGIG but I'm lost how to translate that to line number and shift up one line number for each instance of that string.
Example input file:
[code].....
View 5 Replies
View Related