have the same column L
Hi all, How can I starndarzied string column to have the same column length for each row. Example filename A135953 D10036050 C135858000 I want add leading zeros and the column length should be 10 I tried awk '{ printf "%010s \n", $1}' filename Got all zeros 00 00 00 00 But I want 000A135953 0D10036050 C135858000 I would appreciate if you help me out. thank you in advance -- View this message in context: http://gnu-bash.2382.n7.nabble.com/have-the-same-column-L-tp19574.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
count
Hi all, I have one folder and this folder contains several folders. Each sub folders contains 5 or 6 files. So i want count the number of rows within each file and produce an output. Assume the main folder called A and it has three subfolders folder1, folder2 and folder3. Folder1 has 4 files: file1, file2, file3 and file4. The same thing is for folder2 and folder3. Assume that file1 has 36 rows ( wc -l file1) =36. Assume that file2 has 50 rows ( wc -l file2) =50. Assume that file3 has 36 rows ( wc -l file3) =120. Assume that file4 has 50 rows ( wc -l file4) =15. I want the output mainfolder subfiolder filename # of rows A Folder1file136 A Folder1 file2 50 A Folder1 file3120 A Folder1 file415 A folder 2 filename1 .. .. .. .. Alast_folderlasfilename... . Can anyone help me out? Thanks in advance -- View this message in context: http://gnu-bash.2382.n7.nabble.com/count-tp16675.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
Re: count
John, After trail and error the following works for me but still has to be refined. find . -type f | while read i; do echo -e "$(dirname ${i}}} | cut -b 3-) $(basename ${i}) $(wc -l ${i})" ; done | cut -d " " -f 1,2,3 1. All the folders that I am interested in are all starts with number 2. I don/t want to go in sub folders 3. Using the above script the results look like teh following 185 name.csv 6506 186 add.csv 480 187 31851513 65 188 add.csv 44131 189 add.txt 44131 Name 1692157077 the first column is the folder name the second column is the file name the last column is the count Row 3 and 5 must be excluded because they don't have proper file name and also the 5th column does not start with number. I want to split the output into two files File one contains only add* and file two should contain name*. I reach to my goal on teh fourth step. Here are thesteps #Step 1 find . -type f | while read i; do echo -e "$(dirname ${i}}} | cut -b 3-) $(basename ${i}) $(wc -l ${i})" ; done | cut -d " " -f 1,2,3 > xyz #Step 2 grep -e "Name" xyz |sort | uniq -c > X_Name #step 3 grep -e "Add" xyz |sort | uniq -c > X_Add #Step 4 join -1 2 -2 2 x_Name X_Add > Want_all ## 2 is the folder name , where the two files are joind together. Do you think there better way of doing this? -- View this message in context: http://gnu-bash.2382.n7.nabble.com/count-tp16675p16683.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
Re: count
Hi all, Thank you very much for providing me more information, I am getting more confused. but learning more. I tried this one, but failed if the folder has more than one file name (eg *.csv) in that folder. find . -maxdepth 2 -mindepth 2 -type f -name '*.csv' -o -name '*.txt' |\ egrep '^\./[0-9]' |\ xargs awk 'ENDFILE {print FILENAME "\t" FNR;}' |\ sed -r 's|^./||;s|/|\t|' |\ xargs -L 1 echo -e "${PWD##*/}\t"??? -- View this message in context: http://gnu-bash.2382.n7.nabble.com/count-tp16675p16699.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
Re: count
Here is another problem with the following script find . \( -iname '*.txt' -o -iname '*.csv' \) -exec bash -c ' for f; do IFS=/ read -ra part <<< "$f" printf "%-10.10s %-10.10s %-20.20s %5d\n" \ "${part[1]}" "${part[2]}" "${part[3]}" "$(wc -l < "$f")" done ' _ {} + _: -c: line 0: unexpected EOF while looking for matching `"' _: -c: line 1: syntax error: unexpected end of file -- View this message in context: http://gnu-bash.2382.n7.nabble.com/count-tp16675p16702.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
Re: Future date
Thank you very much! So easy, I am just learning about bash scripting. date -d 'next month' +%b%Y What would happen in December 2016. Will it give me Jan2017? Val! On Sunday, January 24, 2016 5:31 PM, Dave Rutherford wrote: On Sun, Jan 24, 2016 at 5:30 PM, Val Krem wrote: > I am trying to get a variable that combines the next month(Feb) and current > year (2016) from the current date [...] > temp_date=$(date | awk -F ' ' '{print $2,$6}' | tr -d ' ') Wow, that's overkill. You don't need the -F ' ' options to awk, since that's the default. You don't need tr to remove the space because awk will happily not print one if you omit the comma. And you don't need awk in the first place because date will handle the desired output directly if you just ask it to. > I got Jan2016. > but I want this "Feb2016" next month and current year. How do I do that? > > Well at the end of the year, I will have another problem ( ie., to change it > to next year) date -d 'next month' +%b%Y Note, I'm not sure that's robust if you call it on, say, the 31st of the month if the next month doesn't have 31 days. It might give you two months from now. Read the man page for date for further enlightenment.