Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Use portion of file name as new file name Post 302988115 by Raul_Rodriguez on Tuesday 20th of December 2016 12:49:29 PM
Old 12-20-2016
RudiC
I have copied exactly what you had on your last reply, here are the results.
Code:
Raul@Raul-PC ~
$ awk -F, '
> BEGIN   {months ["JAN"]="AP01"; months ["FEB"]="AP02"; months ["MAR"]="AP03";
>          months ["APR"]="AP04"; months ["MAY"]="AP05"; months ["JUN"]="AP06";
>          months ["JUL"]="AP07"; months ["AUG"]="AP08"; months ["SEP"]="AP09";
>          months ["OCT"]="AP10"; months ["NOV"]="AP11"; months ["DEC"]="AP12";
>         }
>         {TMP = FILENAME
>          sub (/\.*$/, "", TMP)
>          print "a_" TMP "_ACTUAL_"months[substr($3,0,3)]"20" substr($3,5,2)"_R                                                                                                               R.txt"
>         }
> ' *.txt
a_STAVOSHFM.txt_ACTUAL_AP062015_RR.txt
a_STAVOSHFM.txt_ACTUAL_AP022016_RR.txt
a_STAVOSHFM.txt_ACTUAL_AP032015_RR.txt
a_STAVOSHFM.txt_ACTUAL_AP052016_RR.txt
a_STHCPSHFM.txt_ACTUAL_AP062015_RR.txt
a_STHCPSHFM.txt_ACTUAL_AP022016_RR.txt
a_STHCPSHFM.txt_ACTUAL_AP032015_RR.txt
a_STHCPSHFM.txt_ACTUAL_AP052016_RR.txt

Raul@Raul-PC ~
$

See depiction for ease
Imageor https://1drv.ms/i/s!AqQovh6lB7bfg0qta9AuWIU87Ajg
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

remove portion of file

Can anyone tell me how to remove a portion of a large file to smaller ones? What I have is a large file that was created becasue several similar files were joined together. Each individual file starts with MSG_HEAD. I want to take everything from MSG_HEAD up to were it says MSG_HEAD again and... (13 Replies)
Discussion started by: methos
13 Replies

2. Shell Programming and Scripting

Separate a portion of text file into another file

Hi, I have my input as follows : I have given two entries- From system Mon Aug 1 23:52:47 2005 Source !100000006!: Impact !100000005!: High Status ! 7!: New Last Name+!100000001!: First Name+ !100000003!: ... (4 Replies)
Discussion started by: srikanth_ksv
4 Replies

3. Programming

Delete Portion of a file

hi i would like to know whether i can delete a part of a file in C for eg. if my file contained 1234567890 and i want to delete 456 so that it becomes 1237890 is there a way i can do this. well, one way i can achieve this is by creating a new file, copy whatever i want, then delete the... (2 Replies)
Discussion started by: sameersbn
2 Replies

4. UNIX for Dummies Questions & Answers

Print a portion of file

Hi, I have a little problem. I am having a file with pattern like : asdf;ffgg;dfjfj;djdfjf;nnjj;djd;ssj; I just want to print the portion from last ";" upto the immediate previous ";". There are several ";" in my line. Please help me out... Thnx in advance (8 Replies)
Discussion started by: vanand420
8 Replies

5. Shell Programming and Scripting

Grep certain portion from the file

Dear Friends, Here I am with another difficulty. I have a flat file from which I wanna grep following pattern. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Statement Date : Blah blah Blah blah Blah blah Blah blah... (1 Reply)
Discussion started by: anushree.a
1 Replies

6. UNIX for Dummies Questions & Answers

Portion of a file in a new files

Hi, I need to devide one file into 3 files based on column numbers and put a string (FILE1, FILE2, FILE3) in the last..... Input file: Column1,Column2,Column3,Column4,Column5,Column6,Column7,Column8,Column9,Column10 Output1: Column1,Column3,Column6,Column4,Column5,FILE1 Output2:... (6 Replies)
Discussion started by: yale_work
6 Replies

7. Shell Programming and Scripting

Rename portion of file based on another file

Hello, I've been searching and reading, but I can't figure out how to solve this problem with my newbie skills. In my directory, I have a list of files (see dirlist.txt attachment) that I need to merge and rename. I have part of the code of the code figured out (see below). However, I... (3 Replies)
Discussion started by: anjulka
3 Replies

8. UNIX for Advanced & Expert Users

Removing portion of file name

Hi , I am getting file name like ABC_DATA_CUSTIOMERS_20120617.dat ABC_DATA_PRODUCTS_20120617.dat Need to convert CUSTIOMERS.dat PRODUCTS.dat Help me how to do this. (7 Replies)
Discussion started by: reach_malu
7 Replies

9. Shell Programming and Scripting

Unix Scripting : Sort a Portion of a File and not the complete file

Need to sort a portion of a file in a Alphabetical Order. Example : The user adam is not sorted and the user should get sorted. I don't want the complete file to get sorted. Currently All_users.txt contains the following lines. ############## # ARS USERS ############## mike, Mike... (6 Replies)
Discussion started by: evrurs
6 Replies

10. UNIX for Dummies Questions & Answers

How to append portion of a file content to another file when a certain pattern is matching?

Hi ladies and gentleman.. I have two text file with me. I need to replace one of the file content to another file if one both files have a matching pattern. Example: text1.txt: ABCD 1234567,HELLO_WORLDA,HELLO_WORLDB DCBA 3456789,HELLO_WORLDE,HELLO_WORLDF text2.txt: XXXX,ABCD... (25 Replies)
Discussion started by: bananamen
25 Replies
BSEARCH(3)						     Linux Programmer's Manual							BSEARCH(3)

NAME
bsearch - binary search of a sorted array SYNOPSIS
#include <stdlib.h> void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); DESCRIPTION
The bsearch() function searches an array of nmemb objects, the initial member of which is pointed to by base, for a member that matches the object pointed to by key. The size of each member of the array is specified by size. The contents of the array should be in ascending sorted order according to the comparison function referenced by compar. The compar rou- tine is expected to have two arguments which point to the key object and to an array member, in that order, and should return an integer less than, equal to, or greater than zero if the key object is found, respectively, to be less than, to match, or be greater than the array member. RETURN VALUE
The bsearch() function returns a pointer to a matching member of the array, or NULL if no match is found. If there are multiple elements that match the key, the element returned is unspecified. CONFORMING TO
SVr4, 4.3BSD, POSIX.1-2001, C89, C99. EXAMPLE
The example below first sorts an array of structures using qsort(3), then retrieves desired elements using bsearch(). #include <stdio.h> #include <stdlib.h> #include <string.h> struct mi { int nr; char *name; } months[] = { { 1, "jan" }, { 2, "feb" }, { 3, "mar" }, { 4, "apr" }, { 5, "may" }, { 6, "jun" }, { 7, "jul" }, { 8, "aug" }, { 9, "sep" }, {10, "oct" }, {11, "nov" }, {12, "dec" } }; #define nr_of_months (sizeof(months)/sizeof(months[0])) static int compmi(const void *m1, const void *m2) { struct mi *mi1 = (struct mi *) m1; struct mi *mi2 = (struct mi *) m2; return strcmp(mi1->name, mi2->name); } int main(int argc, char **argv) { int i; qsort(months, nr_of_months, sizeof(struct mi), compmi); for (i = 1; i < argc; i++) { struct mi key, *res; key.name = argv[i]; res = bsearch(&key, months, nr_of_months, sizeof(struct mi), compmi); if (res == NULL) printf("'%s': unknown month ", argv[i]); else printf("%s: month #%d ", res->name, res->nr); } exit(EXIT_SUCCESS); } SEE ALSO
hsearch(3), lsearch(3), qsort(3), tsearch(3) COLOPHON
This page is part of release 3.25 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. 2003-11-01 BSEARCH(3)
All times are GMT -4. The time now is 01:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy