Hello,
I want to add "0" to the number part of each string to make them equal length for sorting. The challenge to me is the number part is in the middle of the string so that CP1_Items are behind CP19_Items as underscore "_" is bigger than number. My string structure is quite formatted with CP[0-9]{1,2}_Items.
Input file:
Output file:
This is quite common for me, sometime there are three or four digits for the numbers. Say I want change CP1_Items to CP001_Items, and CP10_Items to CP010_Items, etc. So that they can be aligned nicely and sorted first by prefix character then by number, i.e. the value of the number part, not number string!.
I thought of back reference again, but could not figure it out by myself. What is the trick for this type of substitution? Thanks a lot! YT
You could sort straight away with:
if the space between column 1 and column 2 consists of 5 spaces, or
if the space between column 1 and column 2 consists of a single TAB.
Output:
---
To make it 4 digits, try this:
or
Last edited by Scrutinizer; 06-25-2012 at 01:23 PM..
This User Gave Thanks to Scrutinizer For This Post:
Thanks bartus, that's what I meant!
and thanks Scrutinizer! Your answer is very detailed, although too comprehensive for me!
Actually the purpose is to do my next loop with increment 1 from 01 to 24, i.e. CP01..CP24, then PP01~PP19 and RP01~RP16. Totally there are 7296 permutations. I did not anticipate this problem until I come across the different file names.
Can I ask another question about increment from 01 to 99 (i.e. 01, 02 ~ 99) by 1 each time in bash/awk?
Thanks a lot again!
I made it comprehensive, because of this passage:
You can change the 4 in the two examples to 2 or 3 or 5 for example to get different 0-padded number widths...
--
Are you trying to enumerate files that are present in a directory?
--
To enumerate in bash
done
Last edited by Scrutinizer; 06-25-2012 at 04:25 PM..
Yes, I want loop thru the directory, and the two-digits numbers are only part of the each file name. Feel need both looping the file names and regexpr to do the job. That's why I want to sort the two digits problem first, then looping the files.
Say, I need to create files according to three dimensions: Firs is Table, then column and row of each Table. I want
If I have File_1111 I could not distinguish from
etc.
So that if I could always use the two digits at the beginning of my BASH script, this problem can be avoided.
I tried search the similar thing, only find hex format examples.
Then, how should I embed your
to my bash script?
Thanks a lot again!
Last edited by yifangt; 06-25-2012 at 05:00 PM..
Reason: More explanation
Hi 2 all,
i have had AIX 7.2
:/# /usr/IBMAHS/bin/apachectl -v
Server version: Apache/2.4.12 (Unix)
Server built: May 25 2015 04:58:27
:/#:/# /usr/IBMAHS/bin/apachectl -M
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_worker_module (static)
... (3 Replies)
Hello.
System : opensuse leap 42.3
I have a bash script that build a text file.
I would like the last command doing :
print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt
where :
print_cmd ::= some printing... (1 Reply)
How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address
and column 3 contains “cc” e-mail address to include with same email.
Sample input file, email.txt
Below is an sample code where... (2 Replies)
I have a file that stores data in pairs of lines, following this format:
line 1: header (preceded by ">")
line 2: sequence
Example.txt:
>seq1 name
GATTGATGTTTGAGTTTTGGTTTTT
>seq2 name
TTTTCTTC
I want to filter out the sequences and corresponding headers for all sequences that are less... (2 Replies)
Discussion started by: pathunkathunk
2 Replies
5. Post Here to Contact Site Administrators and Moderators
Majority of the questions are pertaining file/string parsing w.r.t
sed
or
awk
It would be nice to have these two as their own sub category under shell-programming-scripting which can avoid lot of duplicate posts. (1 Reply)
Hi All,
Need you help.
I have HPUX “bdf” output, I need % to be align to right side. if you see there are long
file systems lv so i cant do column formatting.
Any idea or best way to align the "%" to be right side.
/dev/emcvg02/lv01 52428800 29931 49123947 0% /abc/disco/iasbin... (7 Replies)
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
Hi Everyone,
# cat a.txt
a;b;c;64O
a;b;c;d;ee;f
# cat a.pl
#!/usr/bin/perl
use strict;
use warnings;
my $tmp3 = ",,a,,b,,c,,d,,e,,f,,";
open(my $FA, "a.txt") or die "$!";
while(<$FA>) {
chomp;
my @tmp=split(/\;/, $_);
if ( ($tmp =~ m/^(64O)/i) || ($tmp... (3 Replies)
Hi Friends,
Can any of you explain me about the below line of code?
mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`
Im not able to understand, what exactly it is doing :confused:
Any help would be useful for me.
Lokesha (4 Replies)