How to add no. from different directory?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to add no. from different directory?
# 1  
Old 02-08-2015
How to add no. from different directory?

Hi Guys,

How to add no. from different directory, my path is below:
Code:
  $ cd sms_files_2/name_files/
  $ wc -l *20150208*
  100000 split_cmp_1-C2014020657_1-T2014020668_20150208034623_ai.csv
  100000 split_cmp_1-C2014020657_1-T2014020668_20150208034623_aj.csv
  100000 split_cmp_1-C2014020671_1-T2014020679_20150208074306_ac.csv
  100000 split_cmp_1-C2014020671_1-T2014020679_20150208074306_ad.csv
   94160 split_cmp_1-C2014020671_1-T2014020679_20150208074306_ae.csv
  100000 split_cmp_1-C2014020672_1-T2014020680_20150208080419_aa.csv
  100000 split_cmp_1-C2014020672_1-T2014020680_2015020809_ab.csv
  694160 total

  $ cd sms_files_3/name_files/
  $ wc -l *20150208*
  100000 split_cmp_1-C2014020657_1-T2014020668_20150208034623_ai.csv
  100000 split_cmp_1-C2014020657_1-T2014020668_20150208034623_aj.csv
  100000 split_cmp_1-C2014020671_1-T2014020679_20150208074306_ac.csv
  100000 split_cmp_1-C2014020671_1-T2014020679_20150208074306_ad.csv
  100000 split_cmp_1-C2014020672_1-T2014020680_20150208080419_aa.csv
  100000 split_cmp_1-C2014020672_1-T2014020680_20150208080419_ab.csv
  600000 total

Where which keywords start from C that is known as camp-id like(1-C2014020657,1-C2014020671, 1-C2014020672 etc. ) and which word
start from T that is known as task-id like(1-T2014020668, 1-T2014020679, 1-T2014020680 etc.)

Now we have to add them corresponding camp-id & task-id, my output like should be below:
Code:
400000   1-C2014020657   1-T2014020668
494160   1-C2014020671   1-T2014020679
400000   1-C2014020672   1-T2014020680


Last edited by aaditya321; 02-08-2015 at 03:59 AM.. Reason: changed quote tags to code tags
# 2  
Old 02-08-2015
Quote:
Originally Posted by aaditya321
Hi Guys,

How to add no. from different directory, my path is below:
Code:
  $ cd sms_files_2/name_files/
  $ wc -l *20150208*
  100000 split_cmp_1-C2014020657_1-T2014020668_20150208034623_ai.csv
  100000 split_cmp_1-C2014020657_1-T2014020668_20150208034623_aj.csv
  100000 split_cmp_1-C2014020671_1-T2014020679_20150208074306_ac.csv
  100000 split_cmp_1-C2014020671_1-T2014020679_20150208074306_ad.csv
   94160 split_cmp_1-C2014020671_1-T2014020679_20150208074306_ae.csv
  100000 split_cmp_1-C2014020672_1-T2014020680_20150208080419_aa.csv
  100000 split_cmp_1-C2014020672_1-T2014020680_2015020809_ab.csv
  694160 total

  $ cd sms_files_3/name_files/
  $ wc -l *20150208*
  100000 split_cmp_1-C2014020657_1-T2014020668_20150208034623_ai.csv
  100000 split_cmp_1-C2014020657_1-T2014020668_20150208034623_aj.csv
  100000 split_cmp_1-C2014020671_1-T2014020679_20150208074306_ac.csv
  100000 split_cmp_1-C2014020671_1-T2014020679_20150208074306_ad.csv
  100000 split_cmp_1-C2014020672_1-T2014020680_20150208080419_aa.csv
  100000 split_cmp_1-C2014020672_1-T2014020680_20150208080419_ab.csv
  600000 total

Where which keywords start from C that is known as camp-id like(1-C2014020657,1-C2014020671, 1-C2014020672 etc. ) and which word
start from T
that is known as task-id like(1-T2014020668, 1-T2014020679, 1-T2014020680 etc.)

Now we have to add them corresponding camp-id & task-id, my output like should be below:
Code:
400000   1-C2014020657   2-T2014020668
494160   1-C2014020671   1-T2014020679
400000   1-C2014020672   1-T2014020680

I don't get it. You say a camp-id keyword starts with C, but all of your examples start with 1-C. Then you say the task-id (which starts from T, but all of your examples start with 1-T and 1 of your requested output task-ids starts with 2-T even though 2-T doesn't appear anywhere in your sample input.

Please explain where the 1- and 2- come from if they are not part of the desired IDs. Please explain why 2-T2014020668 appears in the output when it does not appear at all in the input.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 02-08-2015
My camp-id is starting from1-C & task-id is starting from 1-T

Last edited by Don Cragun; 02-08-2015 at 05:08 AM.. Reason: Change QUOTE tags to ICODE tags.
# 4  
Old 02-08-2015
I repeat: Please explain why 2-T2014020668 appears in the output when it does not appear at all in the input.

How are we supposed to produce the output:
Code:
400000   1-C2014020657   2-T2014020668
494160   1-C2014020671   1-T2014020679
400000   1-C2014020672   1-T2014020680

when 2-T2014020668 never appears in your sample input? Where does the 2-T2014020668 come from?
# 5  
Old 02-08-2015
Sorry for these mistake, we have change it 2-T2014020668 and don't consider it, please consider only 1-T2014020668
# 6  
Old 02-08-2015
Assuming that all of your filenames follow the same pattern, you could try something like:
Code:
#!/bin/ksh
date=$(date +"%Y%m%d")
(	cd sms_files_2/name_files/
	wc -l *$date*
	cd -
	cd sms_files_3/name_files/
	wc -l *$date*
) | awk -F'[ _]*' '
substr($5, 3, 1) == "C" && substr($6, 3, 1) == "T" {
	c[$5 "   " $6] += $2
}
END {	for(i in c)
		printf("%d   %s\n", c[i], i)
}' | sort -k2

which, with your sample input, produces the output:
Code:
400000   1-C2014020657   1-T2014020668
494160   1-C2014020671   1-T2014020679
400000   1-C2014020672   1-T2014020680

If the output order doesn't have to be sorted, remove the:
Code:
 | sort -k2

from the last line of the script.

Although written and tested using the Korn shell, this script will work with any POSIX-conforming shell such as bash and ksh.

If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Add directory to path permanently

I ssh in and am trying to add a directory permanently to $PATH in centos 7 and having issues. My current $PATH is echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin but when I do a sudo nano ~/.bashrc # .bashrc # User specific aliases and functions alias... (7 Replies)
Discussion started by: cmccabe
7 Replies

2. Shell Programming and Scripting

Add part of directory name to filename

Hello, I need to add a part of folder name to the files inside it. For instance the file is HMCBackup_20150430.155027.tgz and it is under directory /nim/dr/HMCBackup/cops22 I need to add cops22 to the file name so as it would be cops22_HMCBackup_20150430.155027.tgz Any help in doing... (10 Replies)
Discussion started by: hasn318
10 Replies

3. Red Hat

How can I add to Active Directory with Samba Linux?

hi How do I update this file /etc/samba/smb.conf Linux be added to Active Directory thanks (0 Replies)
Discussion started by: mnnn
0 Replies

4. AIX

Can we add multiple groups to a directory or a file ?

Hello, drwxr-x--- 21 root system 4096 Jan 25 10:20 /testdir here owner is root, group is system. 1) is it possible to add multiple groups to "/testdir" files/directories ? if yes, please provide me the command. my requirement is to provide read-only access to user1 on /testdir... (6 Replies)
Discussion started by: aaron8667
6 Replies

5. Shell Programming and Scripting

Can't add directory to path correctly

Hello everyone I am a newcomer to UNIX and I have hit a snag in something that would probably take experienced people about 30 seconds. Long story short I am trying to add a directory to my PATH and it is getting added but not working. I mean, the object of adding it to the path is so I can access... (2 Replies)
Discussion started by: tastybrownies
2 Replies

6. UNIX for Dummies Questions & Answers

Add directory to a global PATH

Guys, I did a search on this but couldn't find any thing. I need to add /home/scadm/scripts to the PATH. If I do the below it works for the session I'm in. If I close it and reopen it doesnt work. PATH=$PATH\:/home/scadm/scripts ; export PATH I also want this path added to all the... (3 Replies)
Discussion started by: miltonrods
3 Replies

7. Shell Programming and Scripting

add user script while looking for directory

sorry didnt see that thread at first thanks (1 Reply)
Discussion started by: pbhound
1 Replies

8. Shell Programming and Scripting

Add 5 lines of code to all the scripts in a directory

Hi Guys, I need some tips on writing a Korn shell script that would look for certain lines of code and replace all the scripts in the directory with a few other lines. I have about 120 scripts that I need to modify. Any suggestions would be appreciated! Thanks, Cool_avi (5 Replies)
Discussion started by: coolavi
5 Replies

9. UNIX for Dummies Questions & Answers

how to add permission of directory to a group

Hi, A simple and silly question on Unix. I have a directory named "a" and I would like to grant permission to group name "text" to access, read and execute my directory. Could anyone help me? Thanks. (2 Replies)
Discussion started by: ahjiefreak
2 Replies

10. UNIX for Advanced & Expert Users

add user, directory, etc. via cgi

Hello All (yes I mean you): I'm a self taught programmer, so please bear with me and my ignorance. What I Am Trying To Do: I am attempting to create a user (and all the accompanying attributes like a home directory, entry in the passwd file, disk quota allotment and skel selection for a... (1 Reply)
Discussion started by: gfoxjr
1 Replies
Login or Register to Ask a Question