General :: Shell Script To Extract Single Report By Pattern Then Both Backward And Forward
Feb 18, 2010
I have to admit that I register to LQ after I failed to search for similar solutions.let me see whether I can explain my problem clearly. I need to extract a single report from a big file. The big file looks something like this:
Report for yyyyyy
Your info 999-9999999
End of Report
[code]....
I need to search for a user provided string, say 999-9999999, in the big file. Then I have to extract the single report. My logic is simple,
1) find 999-9999999
2) backward search for "Report for", note down the line number
3) forward search for "End of Report", note down the line number
4) extract the record by using info found from step 2) and 3).
I am trying to do this in bash, with awk and sed (I am new to both).
View 8 Replies
ADVERTISEMENT
Jun 11, 2010
Suppose you have glibc 2.5 compiled with kernel headers 2.6.18. Is it safe to run this glibc with Linux kernel 2.6.32? Is it safe to run this glibc with Linux kernel 2.6.9?
View 1 Replies
View Related
Nov 22, 2010
I have several (vhdl) files containing a pattern with newline characters that I need to replace by another pattern that also contains newline characters.
I start with something like:
Code:
I want to replace it by something like:
Code:
(I need to paste some lines)
As I need to do this (very) often I want to use a shell script.
I tried:
1.
Code:
result:
Code:
2.
Code:
result:
File remains unchanged
3.
Code:
result:
Code:
4.
Code:
result:
Displays the unchanged testfile
How I can automate the pattern replacement?
Code:
View 9 Replies
View Related
Apr 18, 2011
Just using shell scripting, how can I insert text into the middle of a file name. The file has a predictable pattern, let's say 3 letters and 3 numbers and I want to insert text in the middle of those 2 patterns. Say ABC123 is the file name. As a result, the file name should be ABC.blah.123
View 2 Replies
View Related
Mar 20, 2011
I'm new to the shell scripting. can any one help in creating shell script for matching the content of the specific variable with file. it should remove that line from the file if line is containing same value as variable and keep the other content as it is.i used grep -v for accomplishing the same. But grep will remove the pattern which is similar.For eg. Assume file "test" contain datas :aaffif i used grep -v command for the pattern "a" to this file this will remove content "aa" from the file. I want the pattern only "a" should remove from the file, if it is existing. otherwise it should throw alert content not exists.
View 5 Replies
View Related
Nov 4, 2010
i have a file name using the following pattern:
PREFIX: AR
SOURCE: LEGACY
DATETIME: YYYYMMDD_HH24MISS
SUFFIX: .txt
sample filename:AR_LEGACY_20101104_105500.txti want to extract the source which is LEGACY in this case. how do i do this using shell?
View 1 Replies
View Related
Jul 22, 2010
I have requirement to delete some log files from a directory if a string"deletethisfile" is found.Then restart the application servers.1. Search for the string ?deletethisfile? in server.log file under a directory, If found 2. Stop that particular server.3. Delete the log file 4. Restart the server.
View 2 Replies
View Related
Mar 24, 2011
I notice that my bittorrent client is capable of automatically setting up port forwards with my router, and I want to know if I can do the same in a shell script. The reason is, that since my router is stupid and won't let me keep static IP addresses (it seems they forced a DHCP refresh every week to make me want to pay for a more expensive model which doesn't), I need to get my computer to change the port forward to follow my computer's changing internal network IP address. I have a couple of port forward manually entered into my router settings for web interfaces to bittorrent etc, but of course these have a good chance of being invalidated at each DHCP refresh cycle.
View 1 Replies
View Related
Jul 18, 2011
I have some code written in VHDL that looks as follows:
Code:
foo = "bar";
foo <= 'bar',
[code]...
View 1 Replies
View Related
Jul 7, 2010
I'm running F 13 and today's updates included updates to Xorg, so I logged out and back in to let them take effect. Ever since then, Firefox has been repeatedly crashing, especially on certain sites. I managed to get the crash reporting tool to report it to Bugzilla, but when I try to go back to add the bug report to this post, Firefox crashes, every single time. Has anybody else found this? If somebody can get to bugzilla.redhat.com and find the report (The email address I use there is joe@zeff.us if it helps.) I'd appreciate having it added as a response to this, so that others can find it and,
View 14 Replies
View Related
Aug 30, 2009
I'm writing a bash script to search html files, and when I find any occurrence of an img src tag like this:
<img src="123-picture-normal.jpg" alt="some random user entered text" border="0">
I want to add a second line below it that looks like:
<img src="123-picture-thumbnail.jpg" alt="some random user entered text" border="0">
All I need to do is duplicate the line but replace "normal" with "thumbnail"
Each file can have multiple img src tags with different numbered jpgs.
I have a feeling this is a job for sed, but I'm struggling with it. Any ideas?
View 2 Replies
View Related
Mar 10, 2011
I just want to know is it possible to extract a single mail from the mail path i.e. /var/mail/root.
for ex. i am having this mail in /var/mail/root.
From root@localhost.localdomain Thu Mar 10 21:47:47 2011
Return-Path: <root@localhost.localdomain>
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by localhost.localdomain (8.13.8/8.13.8) with ESMTP id p2AGHlx4004190
for <root@localhost.localdomain>; Thu, 10 Mar 2011 21:47:47 +0530
[Code]....
how to extract only this mail from /var/mail/root
View 2 Replies
View Related
Mar 7, 2010
In transparent gateway mode can postfix forward single message to two different destinations with the help of transport file?
View 2 Replies
View Related
Oct 11, 2010
I want to go through a log file and find pattern1 and then a pattern2 only after pattern 1.So for example I want to know howManyRecords was in 13:30.I figured I grep for "start time for the job" and then only after that (and before the next occurence of that) grep for "howManyRecords". Is this a sane way?
View 1 Replies
View Related
Aug 5, 2010
I need to execute 20 urls in one shell script and display there responses on the console and write on text file too. consider the case when url is not responding.
View 4 Replies
View Related
Feb 1, 2010
I am looking for a program to extract a single instrument (guitar) for the purpose of learning to play it.
I don't care if it costs $ or not as long as it is native to UBUNTU 9.10 .
View 8 Replies
View Related
Aug 31, 2010
`cat /var/log/secure | grep "refused connect" |awk '{print $9}'|sed 's/::ffff://g'|uniq -c | sort -nr |head -2 | awk '{print $2}' >/root/sample`
for IP in `cat /root/sample`;
[code]...
View 1 Replies
View Related
Sep 16, 2010
I have such a file(test.txt):
abc 123 456
abc 256 145
axd 125 225
[code]...
View 8 Replies
View Related
Apr 12, 2010
I am trying to create a shell script, on taking a input file as parameter, which need to do 3 things
1) create a copy of existing file.
2) add a new line to the copied file.
3) strip off all the absolute paths inside the copied file
The first 2 points are straight forward. but i am finding it difficult to acheive the 3rd point. myself not very good with awk and sed. but gave it a shot in vain. For example, the input script consists of below,
PROGRAM=`/usr/bin/basename $0`
HOST=`/usr/bin/uname -n`
echo Start $PROGRAM `/usr/bin/date` |
/usr/bin/tee -a $LOG
The output of the script should look like,
PROGRAM=`basename $0`
HOST=`uname -n`
echo Start $PROGRAM `date` |
tee -a $LOG
View 14 Replies
View Related
Feb 12, 2010
My rquirement is I have a flat file with lot of lines on it.example:
line1
line2
line3
[code]....
View 8 Replies
View Related
Feb 24, 2010
I want to search a file for a particular pattern and if pattern found replace the line with new text. i am using awk 'match($0,"pattern") != 0 {print $0} ' filename to check if the pattern exists.how do i get the line number of the pattern and delete that line and replace the line with my new text?
View 1 Replies
View Related
Apr 29, 2010
I have to enhance the behaviour of a backup script written in perl. I don't need to change it, what I need to do is to create a bash script that does some checks like file name and file size, execute the backup script then check if the backup files match the original files.Here's how I try to do it:
- read the files from the original files folder
- store them in an array
- search in the array the files that have a specific file extension
- store the file names that match the search pattern (I know the backup script skips some files so I can hardcode the search pattern)
- run the backup script
- read the files from the backup folder
- store them in an array
- compare the original files name and size stored in an array with those from the backup folder
- send a report email
View 3 Replies
View Related
Aug 20, 2010
I'm looking for a way to insert an SD memory card into my computer and have it copy the files from it (a specific directory) in the background while I view the images from the desktop.
View 2 Replies
View Related
Jul 9, 2009
parsing xml file using shell script and generate report in a PDF file
Xml file input:
<report>
<student name="x" father name="x1" class="first" Address="xyz">
<property name="sports" value="yes"/>
<property name="drawing" value="no"/>
[code]....
View 12 Replies
View Related
Feb 11, 2010
I have upgraded my machine to Karmic, and thereby getting gcc/g++ 4.4 in the process. I have some code that requires gcc/g++ 4.3.
I can change the compiler system wide by redirecting the symbolic link from 4.4 to 4.3
Code:
sudo rm /usr/bin/gcc
sudo ln -s /usr/bin/gcc-4.3 /usr/bin/gcc
but i would like to have it done per session instead.
View 9 Replies
View Related
Jan 25, 2011
I have a slave node uploading all kinds of backups to my server in the internet. Now I would like to display the actual upload and download rate to this server (not the entire nic-traffic, any protocol) in a small php-page for easy monitoring.I had a look at quite some monitoring tools and the one which kind of offers what I am looking for is iftop with a filter on the IP of my server. As I would like to periodically update a file with the actual rates, an interactive program won't do. A possibility would be to filter the packages myself using but this seems to be quite a long shot.The optimal solution would be a program or script printing out the actual upload to a host specified in the options to STDOUT
View 3 Replies
View Related
Aug 5, 2011
Does anyone know of a way to single-step through Bash shell scripts in order to debug? (similar to the way Windows 98 used to let you single-step through autoexec.bat)
View 2 Replies
View Related
Mar 10, 2011
How do i take a single line of input from the user in a shell script?
View 3 Replies
View Related
Mar 22, 2010
I want to write a single shell script that allows me to, once executed from a panel launcher, change the image preview setting between "local files only" and never. Right now i have two tiny scripts, one for local files only and another one for never, that is:
[Code]...
and the other says string "local_only". But that means i need to have two launchers, because i don't know how to write the condition <<when set to never, change it to local only. And is it possible to make a script that also changes the launcher's icon when the preview config is set to one or the other value? That way i'd know what it is set to just by looking at it. It would act as a diagnostic and therapeutic tool XD
View 9 Replies
View Related
Feb 15, 2011
I want to cut out part of the 'uptime' output so all it displays is the load average. In the end I want to cut out everything before the word 'load'. I am a total sed newbie and could really use some examples or links. I've googled and haven't found anything useful yet.##edit###I used the 'cut' command- The code was Code:uptime |cut -d, -f 2,3,4,5 |cut 13-
View 5 Replies
View Related