Sponsored Content
Top Forums Shell Programming and Scripting Help with awk/shell script needed! Post 302127593 by inditopgun on Wednesday 18th of July 2007 05:31:11 PM
Old 07-18-2007
Help with awk/shell script needed!

I have a shell script which reads a file named filelist.txt, containing a list of fully qualified filenames (with complete path), and then does some processing based on the file extension. In order to do the processing, I have to know the file extension, the filename without extension and just the filename_with_extension(excluding the full path)

some sample lines in the filelist.txt looks like this
/home/johndoe/test/a.java
/home/rwilliams/test2/b.xml

My script looks like below (basically I am using awk and relying on "." to give me the extension and filename_without_extension

#!/bin/sh

for cfilename in `cat filelist.txt`
do
file_extension=`echo $cfilename | awk -F\/ '{print $NF}' | awk -F. '{print $NF}'`
export file_extension
filename_wo_ext=`echo $cfilename | awk -F\/ '{print $NF}' | awk -F. '{print $1}'`
export filename_wo_ext
filename_with_ext=$filename.$file_extension
export filename_with_ext
<processing logic>
done

The problem is this script works fine for normal files with names like /home/johndoe/test/a.java
however whenever I encounter files with names like /home/john.doe/test/abcd.efgh.ijkl.mnop.qrst.xml
the script throws up as it relies heavily on the "." character embedded in the name to be the separator between the extension and filename.

Any help will be really appreciated!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script help needed

I am trying to query a table having 3 columns, the third column is a field of varchar(1024) with a SQL string in it. I am using cut command to split out the three fields into three variables. I do a db2 command to extract the data into a file. My problem is with the third field having the SQL... (3 Replies)
Discussion started by: fastgoon
3 Replies

2. UNIX for Dummies Questions & Answers

shell script Help Needed!!

Hi guys-- Here is the interesting problem.. I have a folder, which has a couple of xml files like ( could be anywhere under the sub folders) ABCD_NA.xml XAYSGD_SC.xml CBV_CA.xml etc I need to peek in each of these xml's and see that the pattern before the _ and after the _ are there... (0 Replies)
Discussion started by: smallu
0 Replies

3. Shell Programming and Scripting

script help needed --- awk?

hello and thanks in advance. I need to consolidate 2 records of data into 1 record. here is a sample of the input: ------------------------------------------------------------------------------------------ totalcount fred thomas 99999.00 88888:00 total 77777.00... (7 Replies)
Discussion started by: scuderiaf1
7 Replies

4. Shell Programming and Scripting

help needed for a shell script

i need to search the starting line example we have -sh shl-js-gd i need to search only starting -sh not the other i have used cmd cat filename | grep '-' but it will check for complete - in the file please help me to search only starting - thank u revenna (0 Replies)
Discussion started by: revenna
0 Replies

5. Shell Programming and Scripting

Help with Shell Script Needed

Hi all, I'm a newbie. I'm thinking of making a shell script which will list a directory for *.csv files and merge all the files into a single file called data.csv. However, i have no idea how to. What i do currently is to manually issue the following command to merge multiple CSV files into... (1 Reply)
Discussion started by: infinity2030
1 Replies

6. Shell Programming and Scripting

Shell script help is needed

I have a file test.txt and i need to grep pattern "A.17" from that file. I know cat test.txt | grep A.17 will return the pattern, but it is returing like # VERSION=A.17 How can i take only A.17 from this if A.17 is found, ... do something if not found ... do something Please... (11 Replies)
Discussion started by: Renjesh
11 Replies

7. UNIX for Dummies Questions & Answers

Help needed with Shell script

Hi I want a script which should basically do 1. If the size of the file is 0kb, send email to some list od ppl 2. if the size of the file is other than 0kb send email to someother list... Pls help (2 Replies)
Discussion started by: win4luv
2 Replies

8. Shell Programming and Scripting

Needed shell script for the following

hi all, i want the script for the following my input is date mm-dd-yyyy i.e 1-4-2012(it doesn't have zeros in the input ,in output it should append zeros and should print the output as defined below) my output should be 2012-04-01(yyyy-dd-mm) if my input is 11-14-2012 then my should be... (7 Replies)
Discussion started by: hemanthsaikumar
7 Replies

9. Shell Programming and Scripting

Help Needed with Shell Script

I need help writing a Unix shell script that does the following: 1) Searches all of the files in a given directory that have the .acl file extension 2) Redirects the output of the search to a column in a .xls or .cvs file (Note: The column name in the spreadsheet file needs to be named... (2 Replies)
Discussion started by: ijmoore
2 Replies

10. Shell Programming and Scripting

Shell script - help needed

I want to take out the Z1 value from the lscfg outpu and use the below command to get it lscfg -vl hdisk0 | grep "Device Specific.(Z1)" | awk -F. '{print $NF}' # lscfg -vpl hdisk0 . . Device Specific.(Z0)........0000063268181002 Device Specific.(Z1)........020064a . And it works,... (2 Replies)
Discussion started by: moorthikv
2 Replies
script(1)							   User Commands							 script(1)

NAME
script - make record of a terminal session SYNOPSIS
script [-a] [filename] DESCRIPTION
The script utility makes a record of everything printed on your screen. The record is written to filename. If no file name is given, the record is saved in the file typescript. See WARNINGS. The script command forks and creates a sub-shell, according to the value of $SHELL, and records the text from this session. The script ends when the forked shell exits or when Control-d is typed. OPTIONS
The following option is supported: -a Appends the session record to filename, rather than overwriting it. NOTES
script places everything that appears on the screen in filename, including prompts. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |Enabled | +-----------------------------+-----------------------------+ SEE ALSO
attributes(5) WARNINGS
script can pose a security risk when used in directories that are writable by other users (for example, /tmp), especially when run by a privileged user, that is, root. Be sure that typescript is not a link before running script. SunOS 5.11 30 Jan 2004 script(1)
All times are GMT -4. The time now is 05:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy