Sponsored Content
Top Forums Shell Programming and Scripting Need to format string to collate data of similar IP address. Post 303042642 by mohtashims on Thursday 2nd of January 2020 01:51:30 AM
Old 01-02-2020
Need to format string to collate data of similar IP address.

I have a string which has IP and data of files for that ip which is printed using the below code: Sample string code below:

Code:
str1="10.9.11.128\n-rwxr-xr-x user1 2019-12-29 17:53 /var/branch/custom/tg.xml 286030210\n10.9.12.129\n-rwxr-xr-x user1 2019-12-29 17:53 /app/branch/custom/tg.xml 286030210\n10.9.20.130\n-rwxr-xr-x user1 2019-12-29 17:53 /web/branch/custom/tg.xml 286030210\n10.9.11.128\n-rwxr-xr-x user1 2019-12-29 17:53 /web/branch/custom/mg.xml 286030210\n-rwxr-xr-x user1 2019-12-29 17:53 /web/branch/custom/nog.xml 999997"

    while read -r fline; do
       echo "$fline" | sed 's/\\n/\n/g'
    done <<< "$str1"

Below is the current output:
Code:
./test.sh 
10.9.11.128
-rwxr-xr-x user1 2019-12-29 17:53 /var/branch/custom/tg.xml 286030210
10.9.12.129
-rwxr-xr-x user1 2019-12-29 17:53 /app/branch/custom/tg.xml 286030210
10.9.20.130
-rwxr-xr-x user1 2019-12-29 17:53 /web/branch/custom/tg.xml 286030210
10.9.11.128
-rwxr-xr-x user1 2019-12-29 17:53 /web/branch/custom/mg.xml 286030210
-rwxr-xr-x user1 2019-12-29 17:53 /web/branch/custom/nog.xml 999997

My requirement is to club file details for similar IPs into one.
Thus my desired output is as below:
Code:
10.9.11.128
-rwxr-xr-x user1 2019-12-29 17:53 /var/branch/custom/tg.xml 286030210
-rwxr-xr-x user1 2019-12-29 17:53 /web/branch/custom/mg.xml 286030210
-rwxr-xr-x user1 2019-12-29 17:53 /web/branch/custom/nog.xml 999997
10.9.12.129
-rwxr-xr-x user1 2019-12-29 17:53 /app/branch/custom/tg.xml 286030210
10.9.20.130
-rwxr-xr-x user1 2019-12-29 17:53 /web/branch/custom/tg.xml 286030210

As you can see file details of "10.9.11.128" are clubbed as a single entry so the IP is not repeated.

This is just a sample ... I may have any number of IPs and any number of files under them as a string.

Can you please suggest how we can achieve this output ?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

converting a tabular format data to comma seperated data in KSH

Hi, Could anyone help me in changing a tabular format output to comma seperated file pls in K-sh. Its very urgent. E.g : username empid ------------------------ sri 123 to username,empid sri,123 Thanks, Hema:confused: (2 Replies)
Discussion started by: Hemamalini
2 Replies

2. Shell Programming and Scripting

bash: convert mac address to 16 character format

Hi there Im not quite sure how i can do this, but i am retrieving the mac address from boxes, which in some instances is arriving in its shortened format (i.e. dropping the leading zeros)... for example 0:3:BA:1:E:84 Im trying to figure out a way of converting the single character... (3 Replies)
Discussion started by: rethink
3 Replies

3. Shell Programming and Scripting

Searching String from set of similar File pattern from the Dir

Guys, Here is the script that searches string from the set of similar files from the log directory, All the file patterns are defined as input file, from where the script should map to those files in the LOG_DIR and should start searching the strings from all those similar files. ... (1 Reply)
Discussion started by: raghunsi
1 Replies

4. Shell Programming and Scripting

IP address to decimal format conversion

I have a file which consist of some class 4 IP address as 172.16.112.50 172.16.112.50 172.16.112.50 172.16.112.100 192.168.1.30 172.16.112.100 172.16.112.50 172.16.112.50 172.16.112.50 i want to store them in pure decimal notations instead of the given dotted decimal formats e.g.... (2 Replies)
Discussion started by: vaibhavkorde
2 Replies

5. Shell Programming and Scripting

appending data from similar files

I am familiar with scripting, but I am trying to see if there is an easy way to append files from similar files into one file. For example, if there is file1_20121201, file1_20121202, file1_20121203, file2_20121201, file2_20121202, file2_20121203 I want to be able to combine all the data from... (3 Replies)
Discussion started by: mrbean1975
3 Replies

6. Shell Programming and Scripting

capturing the value in file before string(*) and the similar value in next line only

I've the output in the file like below. I want to capture the value in file before string(*) and the similar value in next line only. cat test1.txt 0003 Not Visible (M) 0 00 03F 0005 Not Visible (M) 0 00 040 - AVAILABLE 0 00... (1 Reply)
Discussion started by: sai_1712
1 Replies

7. Shell Programming and Scripting

Kindly check:remove duplicates with similar data in front of it

Hi all, I have 2 files containing data like this: so if there is same entry repeated in the column like1,2,3,4 I have to check if there is different entries column like 2,4 but similar entries for duplicatein column 2 like1,3 the output shuld be like this for first file ... (5 Replies)
Discussion started by: manigrover
5 Replies

8. Shell Programming and Scripting

To search for a particular tag in xml and collate all similar tag values and display them count

I want to basically do the below thing. Suppose there is a tag called object1. I want to display an output for all similar tag values under heading of Object 1 and the count of the xmls. Please help File: <xml><object1>house</object1><object2>child</object2>... (9 Replies)
Discussion started by: srkmish
9 Replies

9. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

10. Shell Programming and Scripting

How to group similar data?

Hello everybody: I want rearrange about 5 million rows (with 300 columns) into groups. Data looks like the following: where there were various experiments (column 2) conducted at different locations (column headers in top row column 4 onwards) in different years (column 1) using instruments... (0 Replies)
Discussion started by: sheetalk
0 Replies
asadmin-list-custom-resources(1AS)				   User Commands				asadmin-list-custom-resources(1AS)

NAME
asadmin-list-custom-resources, list-custom-resources - gets all the custom resources SYNOPSIS
list-custom-resources --user admin_user[--password admin_password] [--host localhost] [--port 4848] [--secure|-s] [--passwordfile filename] [--terse=false] [--echo=false] [--interactive=true] Gets all the custom resources. This command is supported in remote mode only. OPTIONS
--user authorized domain application server administrative username. --password password to administer the domain application server. --host machine name where the domain application server is running. --port port number of the domain application server listening for administration requests. --secure if true, uses SSL/TLS to communicate with the domain application server. --passwordfile file containing the domain application server password. --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. --interactive if set to true (default), only the required password options are prompted. Example 1: Using list-custom-resources asadmin> list-custom-resources --user admin1 --password adminadmin1 --host pigeon --port 5001 sample_custom_resource Where: sample_custom_resource is the custom resource listed. EXIT STATUS
0 command executed successfully 1 error in executing the command asadmin-create-custom-resource(1AS), asadmin-delete-custom-resource(1AS) J2EE 1.4 SDK March 2004 asadmin-list-custom-resources(1AS)
All times are GMT -4. The time now is 09:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy