data local_cd_httpd
data local_cd
new local_cd_mysql
new local_cd_nagios_content
Awk command I try:
[home@user]ls *.txt | awk -F"_" '{print $1}' > tmp1
[home@user]cat tmp1
data
data
new
new
I able to generate the command 1 of my desired output file with awk.
Column 2 of the desired output file is exclude those content that appear before the first "_" and remove the "*.txt" extension too.
It would be better that the script is written in perl.
Thanks for any advice!
$ echo '!/^c/ {sub(/_/,"\t"); print}'|a2p
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if $running_under_some_shell;
# this emulates #! processing on NIH machines.
# (remove #! line above if indigestible)
eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_0-9]+=)(.*)/ && shift;
# process any FOO=bar switches
$, = ' '; # set output field separator
$\ = "\n"; # set output record separator
while (<>) {
chomp; # strip record separator
if (!/^c/) {
s/_/\t/;
print $_;
}
}
^[^c]
The 1st ^ stands for start of line.
The other ^ inside the square brackets (group of characters) is a negation of the characters inside the bracket ie. the group of characters, which is here just the c. It just means "All characters but a c that start the line".
In other word, can I said that as long as the first character of my content is not start with "c", it will replace the first "_" with "\t", am I right?
$ perl -F_ -lane 'printf("%s\t",$F[0]); shift @F; for(@F){s/.txt//;}print join("_",@F)' input.txt
campus.com icmp_ping_alive
data local_cd_httpd
data local_cd
new local_cd_mysql
new local_cd_nagios_content