Sponsored Content
Top Forums Shell Programming and Scripting AWK Duplicate lines multiple times based on a calculated value Post 302534582 by aigles on Tuesday 28th of June 2011 08:18:50 AM
Old 06-28-2011
A possible solution :
Code:
awk -F, '
   {
      c = int(($2+23)/24);
      i = 1;
      fmt = "";
      while (c--) {
         printf "%s" fmt "\n", $1, i++;
         fmt = "(%d)"
      }
   }
' inputfile.csv

inputfile.csv :
Code:
domain.com/categories/shopping/shoes/,197
domain.com/categories/shopping/shorts/,58
domain.com/categories/shopping/ties/,5

Output :
Code:
domain.com/categories/shopping/shoes/
domain.com/categories/shopping/shoes/(2)
domain.com/categories/shopping/shoes/(3)
domain.com/categories/shopping/shoes/(4)
domain.com/categories/shopping/shoes/(5)
domain.com/categories/shopping/shoes/(6)
domain.com/categories/shopping/shoes/(7)
domain.com/categories/shopping/shoes/(8)
domain.com/categories/shopping/shoes/(9)
domain.com/categories/shopping/shorts/
domain.com/categories/shopping/shorts/(2)
domain.com/categories/shopping/shorts/(3)
domain.com/categories/shopping/ties/

Jean-Pierre.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding duplicate lines and deleting folders based on them

Hi, I have research data, which is organized to 100 folders numbered 00-99. I have many sets of 100 folders, for different values of initial parameters. For some reason, the computer that ran the program to gather the data, didn't always create a unique seed for each folder. I anticipated that... (1 Reply)
Discussion started by: Jopi
1 Replies

2. Shell Programming and Scripting

Sed or Awk for lines between two strings multiple times and keep the last one

Hi, I am trying to get lines between the last occurrences of two patterns. I have files that have several occurrences of “Standard” and “Visual”. I will like to get the lines between “Standard” and “Visual” but I only want to retain only the last one e.g. Standard Some words Some words Some... (4 Replies)
Discussion started by: damanidada
4 Replies

3. Shell Programming and Scripting

Scripting to Duplicate Lines Based on Variable

Greeting all! I could use some assistance please. :) I've been searching for the best way to duplicate a line based on a variable in the next line. Sample Data: Nov 22 00:00:19 10.10.10.1 "%ASA-4-313005: No matching connection for ICMP error message: icmp src Outside:1.2.3.4 dst... (3 Replies)
Discussion started by: sjrupp
3 Replies

4. UNIX for Dummies Questions & Answers

Extracting data between specific lines, multiple times

I need help extracting specific lines in a text file. The file looks like this: POSITION TOTAL-FORCE (eV/Angst) ----------------------------------------------------------------------------------- 1.86126 1.86973 1.86972 ... (14 Replies)
Discussion started by: captainalright
14 Replies

5. Shell Programming and Scripting

awk to find lines containing word that occur multiple times

i have a script that scans a log file every 10 minutes. this script remembers the last line of the log and then uses it to continue monitoring the log when it runs again 10 minutes later. the script searches the log for a string called MaxClients. now, how can i make it so that when the... (7 Replies)
Discussion started by: SkySmart
7 Replies

6. UNIX for Dummies Questions & Answers

awk solution to duplicate lines based on column

Hi experts, I have a tab-delimited file with one column containing values separated by a comma. I wish to duplicate the entire line for every value in that comma-delimited field. For example: $cat file 4444 4444 4444 4444 9990 2222,7777 6666 2222 ... (3 Replies)
Discussion started by: torchij
3 Replies

7. Shell Programming and Scripting

Remove duplicate lines from file based on fields

Dear community, I have to remove duplicate lines from a file contains a very big ammount of rows (milions?) based on 1st and 3rd columns The data are like this: Region 23/11/2014 09:11:36 41752 Medio 23/11/2014 03:11:38 4132 Info 23/11/2014 05:11:09 4323... (2 Replies)
Discussion started by: Lord Spectre
2 Replies

8. Shell Programming and Scripting

Awk: Combine multiple lines based on number of fields

If a file has following kind of data, comma delimited 1,2,3,4 1 1 1,2,3,4 1,2 2 2,3,4 My required output must have only 4 columns with comma delimited 1,2,3,4 111,2,3,4 1,222,3,4 I have tried many awk command using ORS="" but couldnt progress (10 Replies)
Discussion started by: mdkm
10 Replies

9. Shell Programming and Scripting

awk joining multiple lines based on field count

Hi Folks, I have a file with fields as follows which has last field in multiple lines. I would like to combine a line which has three fields with single field line for as shown in expected output. Please help. INPUT hname01 windows appnamec1eda_p1, ... (5 Replies)
Discussion started by: shunya
5 Replies

10. Shell Programming and Scripting

Remove duplicate lines which has been repeated 4 times

Remove duplicate lines which has been repeated 4 times attached test.txt below command tried and not getting expect output. for i in `cat test.txt | uniq` do num=`cat test.txt | grep $i | wc -l` echo $i $num done test.txt ... (17 Replies)
Discussion started by: Kalia
17 Replies
asadmin-stop-domain(1AS)					   User Commands					  asadmin-stop-domain(1AS)

NAME
asadmin-stop-domain, stop-domain - stops the given domain SYNOPSIS
stop-domain [--domaindir install_dir/domains][--terse=false] [--echo=false] [domain_name] stop-domain stops the specified domain. If there is only one domain in the default domain directory (install_dir/domains), then no operand is required to stop the domain. However, if there is more than one domain, the domain operand must be specified. This command is supported in local mode only. OPTIONS
--domaindir directory where the domain is to be stopped. If specified, path must be accessible in the filesystem. If not speci- fied, the domainis stopped in the default install_dir/domains directory. --terse indicates that any output data must be very concise, typically avoiding human-friendly sentences and favoring well- formatted data for consumption by a script. Default is false. --echo setting to true will echo the command line statement on the standard output. Default is false. OPERANDS
domain_name name of the domain. Must be a unique name. Example 1: Using stop-domain asadmin> stop-domain sampleDomain Stoping Domain sampleDomain, please wait Domain sampleDomain stopped Command stop-domain executed successfully Where: the sampleDomain domain in the default domains directory is stopped. EXIT STATUS
0 command executed successfully 1 error in executing the command asadmin-create-domain(1AS), asadmin-delete-domain(1AS), asadmin-start-domain(1AS), asadmin-list-domains(1AS) J2EE 1.4 SDK March 2004 asadmin-stop-domain(1AS)
All times are GMT -4. The time now is 09:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy