Text extraction


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Text extraction
# 1  
Old 08-29-2013
Wrench Text extraction

Dear All,
I am trying to extract text from a file containing cron entries.


Code:
cat /var/tmp/cron_backups/debmed_tmp
< * * * * * /bell
> * * * * * /belly

what I am trying to do is create two text files containing all entries that begin with < and another text files containing entries with > .
here is a rough outline on how I intend to achieve it .

Code:
for i in `cat /var/tmp/cron_backups/debmed_tmp`; do echo $i | awk '{print $1}'; done
<
debmed_check.ksh
test.ksh
debmed_check.ksh
test.ksh
debmed_check.ksh
test.ksh
debmed_check.ksh
test.ksh
debmed_check.ksh
test.ksh
/bell
>
debmed_check.ksh
test.ksh
debmed_check.ksh
test.ksh
debmed_check.ksh
test.ksh
debmed_check.ksh
test.ksh
debmed_check.ksh
test.ksh
/belly


I just want the output :
<
>

inorder to apply an if statement checking the first column of every row. The code does not seem to work and returns the file names in the directory /var/tmp/cron_backups/ .

Kindly help
# 2  
Old 08-29-2013
This code copies lines starting with < to file1.txt and lines starting with > to file2.txt

Code:
awk -vf1=file1.txt -vf2=file2.txt '/^</ {print > f1} /^>/ {print > f2}' filename

# 3  
Old 08-29-2013
Thankyou.
This is the output I get:

Code:
awk -vf1=file1.txt -vf2=file2.txt '/^</ {print > f1} /^>/ {print > f2}' /var/tmp/cron_backups/debmed_tmp
awk: can't open file 
 record number 1

# 4  
Old 08-29-2013
A few checks you can do:

1. Ensure you have read permission on file /var/tmp/cron_backups/debmed_tmp
2. Ensure you have write permission to present working directory because the files file1.txt and file2.txt will be created in current directory.
# 5  
Old 08-29-2013
Both the file and the folder have 777 permissions.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed text extraction between 2 patterns using variables

Hi everyone! I'm writting a function in .bashrc to extract some text from a file. The file looks like this: " random text Begin CG step 1 random text Begin CG step 2 ... Begin CG step 100 random text" For a given number, let's say 70, I want all the text between "Begin CG... (4 Replies)
Discussion started by: radudownload
4 Replies

2. Shell Programming and Scripting

awk - horizontal and vertical text extraction

Hi, I need some help in getting extracting the specific horizontal and vertical texts in a single line. I am trying to extract few of the parameters from a config file. Your help is appreciated. Desired Output ---------------- Pool members members ... (4 Replies)
Discussion started by: pratheeshp
4 Replies

3. Shell Programming and Scripting

extraction

I have following input @xxxxxx@ I want to extract what's between @....@ that is : xxxx using SED command (6 Replies)
Discussion started by: xerox
6 Replies

4. Shell Programming and Scripting

Extraction of text using sed or awk command

Hi All, I need to extract 543 from the command below : # pvscan PV /dev/sdb1 VG vg0 lvm2 Total: 1 543.88 GB] / in use: 1 / in no VG: 0 I have the following command which does the job, but I think this could be achieved in a more simple way using sed or awk. Any help is... (7 Replies)
Discussion started by: nua7
7 Replies

5. Shell Programming and Scripting

Extraction of data from multiple text files, and creation of a chart

Hello dear friends, My problem as explained below seems really basic. Fact is that I'm totally new to programming, and have only a week to produce a script ( CShell or Perl ? ) to perform this action. While searching on the forums, I found a command that could help me, but I don't know... (2 Replies)
Discussion started by: ackheron
2 Replies

6. UNIX for Dummies Questions & Answers

String extraction from a text file

The following script code works great for extracting 'postmaster' from a line of text stored in a variable named string: string="PenaltyError:=554 5.7.1 Error, send your mail to postmaster@LOCALDOMAIN" stuff=$( echo $string | cut -d@ -f1 | awk '{ print $NF }' ) echo $stuff However, I need to be... (9 Replies)
Discussion started by: cleanden
9 Replies

7. UNIX for Advanced & Expert Users

extraction of data from a text file which follows certain pattern

hi everybody, i have a file, in it I need to extract some data that follows a particular pattern.. For example: my file contains like now running Speak225 sep 22 mon 16:34:05 2008 -------------------------------- ... (4 Replies)
Discussion started by: mohkris
4 Replies

8. Shell Programming and Scripting

extraction of perfect text from file.

Hi All, I have a file of the following format. <?xml version='1.0' encoding='utf-8'?> <tomcat-users> <role rolename="tomcat"/> <role rolename="role1"/> <role rolename="manager"/> <role rolename="admin"/> <user username="tomcat" password="tomcat" roles="tomcat"/> <user... (5 Replies)
Discussion started by: nua7
5 Replies

9. Shell Programming and Scripting

Shell script for text extraction from a file

Hi All, I am new to Shell Scripting. I have a file consisting of XML messages.Each message is associated with a timestamp value(it is not a xml field).I need to extract\copy all messages in a particular time interval and put in another new file using Shell Scripting. My XML looks like... (3 Replies)
Discussion started by: vignesh53
3 Replies
Login or Register to Ask a Question