Sponsored Content
Full Discussion: Unix File name manipulation
Operating Systems AIX Unix File name manipulation Post 302560712 by mrn6430 on Friday 30th of September 2011 03:55:18 PM
Old 09-30-2011
Bug

I figured it out on my own after I posted this. It is working. Here is how I did it:

I have files coming like this: 08101101.wsp ...etc I finally got it to work to write out the file per specs as:
Code:
    08078-110810-H00044-C01W.835

and her is the code I came up with and it works:
Code:
GetFileName=08
 
#First loop to add 08078 at the begining of the file and and H00044-C.835 # at the end:
for file in $GetFileName*.*; do
     newfile=`echo 08078-$file-H00044-C.835`
     mv $file ./$newfile
done
 
# 2nd For loop to only keep one extention on the file name
for file in 08078-*.835; do
     newfile=`echo $file | awk -F'.' 'BEGIN{OFS=""}{s=$NF;o=$0;$NF="";print "mv "o" " $0"."s}'|sh`
done
 
# 3rd For loop to re-arrange how to rename the file:
for file in 08078-*.835; do
     GetNumb=`echo $file  | cut -c1-5`
     Getmmdd=`echo $file  | cut -c7-10`
     GetYear=`echo $file  | cut -c11-12`
     GetSeq=`echo $file   | cut -c13-15`
     GetIns=`echo $file   | cut -c19-24`
     GetChar=`echo $file  | cut -c26-26`
     GetRest=`echo $file  | cut -c 27-`
     NewFile=$GetNumb-$GetYear$Getmmdd-$GetIns-$GetChar$GetSeq$GetRest
     mv $file ./$NewFile
done

It works for what I want it to do. Is there a better way to do this "Maybe with one for loop vs. 3 loops ?



Thanks


Moderator's Comments:
Mod Comment Please use code tags

Last edited by zaxxon; 10-10-2011 at 05:26 AM.. Reason: code tags, see PM
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unix Shell Novice - File Manipulation

Hi, I am brand new to unix and am hoping someone can start me in the right direction. I want to be able to put the results of a file command such as wc -l filename into a variable which I can then use to test against another variable...i.e. I need to show the nth line of a file, but need to... (3 Replies)
Discussion started by: nmullane
3 Replies

2. Linux

string manipulation in unix

Hi, I have a question . I have script which gets info from db2 engine. The script is cat sample_substitute.sh CNTR_NM=`db2 -x "select CONTAINER_NAME ,usable_pages from table( SNAPSHOT_CONTAINER('TST103',-1)) as SNAPSHOT_CONTAINER, syscat.tablespaces where tablespace_name = tbspace and... (3 Replies)
Discussion started by: capri_drm
3 Replies

3. UNIX for Dummies Questions & Answers

String manipulation in Linux & Unix (Solaris)

Guy I have this below report and I need someone help me formatting it SID File Name Started Finished Backup ABC XYZ.log 10Sep09-012857\n 10Sep09-020748 Successful I need Started & Finished columns to be formatted as ... (1 Reply)
Discussion started by: anjum.suri
1 Replies

4. UNIX for Dummies Questions & Answers

UNIX - File/Table/Data manipulation

Hi, I have a table (e.g.): a 1 e 4 5 6 b 2 r 4 4 2 c 5 r 3 7 1 d 9 t 4 4 9 . . What I need to do is to set the values of some values in column 2 to negative values. For example, the values 2 and 9 should become -2 and -9 in the modified file. How should I go about... (2 Replies)
Discussion started by: pc2001
2 Replies

5. UNIX for Dummies Questions & Answers

Filtering records from 1 file based on some manipulation doen on second file

Hi, I am looking for an awk script which should help me to meet the following requirement: File1 has records in following format INF: FAILEd RECORD AB1234 INF: FAILEd RECORD PQ1145 INF: FAILEd RECORD AB3215 INF: FAILEd RECORD AB6114 ............................ (2 Replies)
Discussion started by: mintu41
2 Replies

6. Shell Programming and Scripting

Awk to convert a text file to CSV file with some string manipulation

Hi , I have a simple text file with contents as below: 12345678900 971,76 4234560890 22345678900 5971,72 5234560990 32345678900 71,12 6234560190 the new csv-file should be like: Column1;Column2;Column3;Column4;Column5 123456;78900;971,76;423456;0890... (9 Replies)
Discussion started by: FreddyDaKing
9 Replies

7. Shell Programming and Scripting

Populating File data with custom manipulation on file names

Hi, I am confused how to proceed firther please find the problem below: Input Files: DCIA_GEOG_DATA_OCEAN.TXT DCIA_GEOG_DATA_MCRO.TXT DCIA_GEOG_DATA_CVAS.TXT DCIA_GEOG_DATA_MCR.TXT Output File Name: MMA_RFC_GEOG_NAM_DIM_LOD.txt Sample Record(DCIA_GEOG_DATA_OCEAN.TXT):(Layout same for... (4 Replies)
Discussion started by: Arun Mishra
4 Replies

8. Shell Programming and Scripting

Manipulation of file data with UNIX

Hello , How all doing today.. I have a little doubt in Unix (6 Replies)
Discussion started by: adisky123
6 Replies

9. Shell Programming and Scripting

Stream manipulation in UNIX shell scripting

i have a file something like this : start: 01:00:00 01:30:00 02:30:00 05:30:00 end: 01:13:00 02:00:00 02:40:00 05:45:00 and i want (end - start) total run time in below format: run: 00:13:00 00:30:00 00:10:00 00:15:00 (4 Replies)
Discussion started by: Acme
4 Replies

10. Shell Programming and Scripting

File Manipulation - UNIX script

Hi, I have a file about 100 lines. Each line is about 2000 characters (each line is fixed length). In middle of each line is following constant value 0000040029892586 Now, I want to go through each line and increment by 1. So, line 1 will have 586 line 2 will have 587, line 3 will have... (4 Replies)
Discussion started by: jakSun8
4 Replies
MSSQL_NUM_FIELDS(3)													       MSSQL_NUM_FIELDS(3)

mssql_num_fields - Gets the number of fields in result

SYNOPSIS
int mssql_num_fields (resource $result) DESCRIPTION
mssql_num_fields(3) returns the number of fields in a result set. PARAMETERS
o $result - The result resource that is being evaluated. This result comes from a call to mssql_query(3). RETURN VALUES
Returns the number of fields, as an integer. EXAMPLES
Example #1 mssql_num_fields(3) example <?php // Connect to MSSQL and select the database $link = mssql_connect('KALLESPCSQLEXPRESS', 'sa', 'phpfi'); mssql_select_db('php', $link); // Select some data from our database $data = mssql_query('SELECT [name], [age] FROM [php].[dbo].[persons]'); // Construct a table echo '<table border="1">'; $header = false; // Iterate through returned results while ($row = mssql_fetch_array($data)) { // Build the table header if (!$header) { echo '<thead>'; echo '<tr>'; for ($i = 1; ($i + 1) <= mssql_num_fields($data); ++$i) { echo '<td>' . ucfirst($row[$i]) . '</td>'; } echo '</tr>'; echo '</thead>'; echo '<tbody>'; $header = true; } // Build the row echo '<tr>'; foreach($row as $value) { echo '<td>' . $value . '</td>'; } echo '</tr>'; } // Close table echo '</tbody>'; echo '</table>'; // Clean up mssql_free_result($data); mssql_close($link); ?> SEE ALSO
mssql_query(3), mssql_fetch_field(3), mssql_num_rows(3). PHP Documentation Group MSSQL_NUM_FIELDS(3)
All times are GMT -4. The time now is 07:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy