script to eliminate left and right fields and to get the ouput.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to eliminate left and right fields and to get the ouput.
# 8  
Old 10-22-2009
Hello ghostdog74, I am not sure what you mean:
Code:
$> echo 'Sun Jan 11 /a.b 11:20:10 2009 1 0 /home/output/file2311_recent.list.list user1.bla user2 0 done' |grep -o '/[^.]*[^ ]*'
/a.b
/home/output/file2311_recent.list.list

# 9  
Old 10-22-2009
pls see below simulation
Code:
$ more file
Sun Jan 11 11:20:10 2009 1 0 /home/output/file2311_recent.list user1 user2 0 done
Sun Jan 11 11:20:10 2009 1 0 /home/output/file2312 jan recent.list firstname.lastname user2 0 done
Sun Jan 11 11:20:10 2009 1 0 /home/output/Output.2313 feb recent.text user1 user2 0 done
$ grep -o '/[^.]*[^ ]*' file
/home/output/file2311_recent.list
/home/output/file2312 jan recent.list
/home/output/Output.2313

first two is ok, last is not. because there is "." in file name. whereas going by fields, results should always be consistent
Code:
#  python -c "for line in open('file'): print ' '.join(line.split()[7:-4])"
/home/output/file2311_recent.list
/home/output/file2312 jan recent.list
/home/output/Output.2313 feb recent.text


Last edited by ghostdog74; 10-22-2009 at 02:48 AM..
# 10  
Old 10-22-2009
All the codes are great, Many Thanks!,
Scrutinizer , thanks for explaining the regular expression, it is crystal clear .

Thanks Ghostdog74 for pointing out the extra dot in file name issue(.)
The idea with eliminating the left and right fields and keeping the desired one makes it perfect. sed is fine except the extra . , nawk couldnt check, rev & python worked very well, Tx. Rveri.
# 11  
Old 10-23-2009
Code:
awk '{for(i=8;i<=NF-4;i++)
        printf $i" "
        printf "\n"
        }'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script ouput conversion

Hi All, I am trying to print all the packages info in solaris 11 using below script. #!/usr/bin/env bash pkginfo -l | egrep '(BASEDIR|NAME|VERSION)' | awk '{print}' > /tmp/cp1 /usr/bin/nawk -F: ' {for (i=1; i<=NF; i++) {gsub (/^ *| *$/, "", $i) ... (5 Replies)
Discussion started by: sravani25
5 Replies

2. Shell Programming and Scripting

Shell Script has different ouput via cron vs when run Manually

Hello Lads, I deployed a script on my mac to start and stop EC2 instances on AWS console. The script when started manually on the terminal does the expected stop and start. Problem is when i try to schedule it on a cron, it fails to recognize the AWS Keys which i set up as ENV variable by... (2 Replies)
Discussion started by: Irishboy24
2 Replies

3. Shell Programming and Scripting

Call a Perl script within a bash script and store the ouput in a .txt file

I'm attempting to write a bash script that will create a network between virtual machines. It accepts three arguments: an RSpec that describes the network topology, and two list of machines (servers and clients). I have a (working) Perl script that I want to call. This Perl script takes an RSpec... (6 Replies)
Discussion started by: mecaka
6 Replies

4. Shell Programming and Scripting

Format Ouput

I have this input file Switch 0; Sun Sep 11 12:40:53 2011 EDT (GMT+4:00) 12:40:53.159984 SCN Port Offline;g=0x1e4b6 A2,P0 A2,P0 379 NA 12:40:53.159991 *Removing all nodes from port A2,P0 A2,P0 379 NA 18:45:31.326604 Port Elp engaged ... (1 Reply)
Discussion started by: greycells
1 Replies

5. Shell Programming and Scripting

Script to eliminate files .rlogin

Hi guys, I'm try making to script for eliminate files rlogins. path1='/home/*' for i in `cat /etc/passwd |awk -F: '{print $6}'`; do if test "$i" = "$path1"; then echo $i cd $i if ; then echo "$i/.rhosts detectado"|mail -s "rhosts" root ... (14 Replies)
Discussion started by: nena_redbalon
14 Replies

6. Shell Programming and Scripting

Limit ouput file on a shell script

I have this one::) doing jstack on JVM proccess. #!/bin/ksh # ---------------------------------------------------- # capture_jstack.sh <INTERVAL> <COUNT> # run jstack and capture output to a log file #----------------------------------------------------- # # scripts and logs are stored... (3 Replies)
Discussion started by: pointer
3 Replies

7. Shell Programming and Scripting

Shell script help to eliminate files of todays date

Hi I am very new to shell scripting and have written a script (below). However the directory I am searching will contain a file with a .trn extension each day which I want to eliminate. Each day the file extension overnight will change to trx, if this fails I want to know. Basically what I... (2 Replies)
Discussion started by: richM
2 Replies

8. UNIX for Dummies Questions & Answers

Combine fields and eliminate white space

Good Morning, Newbie here. Could someone help with shell scripting that will enable me to combine 2 fields into one eliminating the white space. The fields are fixed but the data of course varies. For example: First Name: "George " 20 positions" Last Name: "Washington " 30 positions" I need... (2 Replies)
Discussion started by: ski
2 Replies

9. Shell Programming and Scripting

Eliminate variable checking in a script

RH Linux, $SHELL=/bin/ksh I have a .profile which I source in as such --> . .profile Whats happening is the variables are getting validated and generating errors. for example .profile export foo=/to/the/moon when I . .profile , I get : not foundmyusername/.profile or bad... (8 Replies)
Discussion started by: BMetelsky
8 Replies

10. Shell Programming and Scripting

capture the ouput!

Hi, my perl script is calling another external java program. The Java in turn prints out a string. how can I capture the string. ------------------ #!/usr/bin/perl print "Content-type:text/html\n\n"; use CGI; $query = new CGI; $theCookie = $query->cookie('someCookie'); $user =... (0 Replies)
Discussion started by: azmathshaikh
0 Replies
Login or Register to Ask a Question