parsing filenames


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers parsing filenames
# 1  
Old 11-04-2008
parsing filenames

How can I loose a part of the filename

I want to drop the “_<Number>.sql”

Below I have a listing of file names in a file

Eg :
CREDIT_DEL_033333.sql I want it to be CREDIT_DEL
ATM_DEBIT_CARD_0999999.sql I want it to be ATM_DEBIT_CARD
DELCC_1234567.sql I want it to be DELCC
ALL_CR_DB_TRANS_444444444444.sql ALL_CR_DB_TRANS
ALL_CR_10_TRANS_444444444444.sql ALL_CR_10_TRANS

Any help is appreciated.
# 2  
Old 11-04-2008
Hammer & Screwdriver how about?

Code:
> echo ALL_CR_DB_TRANS_444444444444.sql | cut -d"." -f1 | sed "s/[0-9]*$//" | sed "s/_$//"
ALL_CR_DB_TRANS

> echo DELCC_1234567.sql | cut -d"." -f1 | sed "s/[0-9]*$//" | sed "s/_$//"
DELCC

# 3  
Old 11-04-2008
Code:
/home/jmcnama> cat inputfile
CREDIT_DEL_033333.sql
ATM_DEBIT_CARD_0999999.sql
DELCC_1234567.sql
ALL_CR_DB_TRANS_444444444444.sql
ALL_CR_10_TRANS_444444444444.sql

/home/jmcnama> sed 's/_[0-9]*\.sql$//' inputfile
CREDIT_DEL
ATM_DEBIT_CARD
DELCC
ALL_CR_DB_TRANS
ALL_CR_10_TRANS

# 4  
Old 11-04-2008
Thankyou guys both of the above worked. cheers
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sort the filenames

Hello Unix experts: I have dir where few files are there, i want to sort these files and write the output to some other file but i need filenames with filepath too eg: i have filenames like 010020001_S-FOR-Sort-SYEXC_20171218_094256_0004.txt so i want to sort my files on first 5 fields of... (2 Replies)
Discussion started by: gnnsprapa
2 Replies

2. UNIX for Dummies Questions & Answers

Parsing filenames - dynamic

I have requirement of parsing file names from given directory based on the pattern ( pattern will be parameter to script and can be any ). for example, user enterred 2 params : directory name : /dirname/ filename_pattern : *.dat_???? and there are 2 files in the directory as... (1 Reply)
Discussion started by: freakabhi
1 Replies

3. Shell Programming and Scripting

Parsing FileNames

Hi, Its been a long time since I've done any shell scripting and I need some help here. Thanks in advance... I need this as a bourne or csh script running under SCO. In a folder I have a list of Backup files named with "TarBackup plus a date and time component suffix" like this; ... (2 Replies)
Discussion started by: stanlyn
2 Replies

4. UNIX for Dummies Questions & Answers

renaming filenames

I have 7 files with 7 different names coming into a specified folder on weekly basis, i need to pick a file one after another and load into oracle table using sql loader. I am using ksh to do this. So in the process if the file has error records and if sql loader fails to load into oracle tables,... (0 Replies)
Discussion started by: vpv0002
0 Replies

5. Shell Programming and Scripting

Extracting filenames

Hi I need to pull out the name of the file from the path. See, here is my loop that gets the files: dsxdir="/var/local/dsx/import" for dsxfile in $dsxdir/*.dsx; do dsxlog $reverb --info --module="$module" "$dsxfile" $dsximp $norule $oprange --dsn=$dsn --dbname=$dbname... (6 Replies)
Discussion started by: ladyAnne
6 Replies

6. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

7. Shell Programming and Scripting

Problem with parsing filenames containing spaces

I tried using the following options to parse the *.sh files in a dir (the name can contain spaces). But each of them breaks: FILESSH=$(ls /mysh/*.sh) echo "$FILESSH" | while read FILE ; do --- do something --; done This does not break for any whitespaces in filenames for FILE in... (1 Reply)
Discussion started by: amicon007
1 Replies

8. UNIX for Dummies Questions & Answers

Backslashes in Filenames

Using a small script, I automatically generated some text logs. The files ended being undownloadable, unopenable and undeletable. Upon further investigation, the files ended up looking like this: log\r log2\r log3\r I've tried a few different things, including double slashing before the... (6 Replies)
Discussion started by: shepherdsflock
6 Replies

9. Shell Programming and Scripting

Perl parsing compared to Ksh parsing

#! /usr/local/bin/perl -w $ip = "$ARGV"; $rw = "$ARGV"; $snmpg = "/usr/local/bin/snmpbulkget -v2c -Cn1 -Cn2 -Os -c $rw"; $snmpw = "/usr/local/bin/snmpwalk -Os -c $rw"; $syst=`$snmpg $ip system sysName sysObjectID`; sysDescr.0 = STRING: Cisco Internetwork Operating System Software... (1 Reply)
Discussion started by: popeye
1 Replies

10. Shell Programming and Scripting

prefixing filenames

Hi,:cool: I have a list of files in a directory.I need to store them in a file with the prefix of @ by using a command.. ex:@p_po.plb @p_ebiz_roster_data.plb any idea pls. cheers RRK (2 Replies)
Discussion started by: ravi raj kumar
2 Replies
Login or Register to Ask a Question