Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Reading a file line by line and print required lines based on pattern Post 303040552 by balu1234 on Thursday 31st of October 2019 11:44:48 AM
Old 10-31-2019
Thanks all for sharing the information.

now i am able to get the required output.
Output :

mounted:"/boot" type:"part" file_system:"/dev/sda1"

mounted:"/" type:"lvm" file_system:"/dev/mapper/centos-root"

mounted:"[SWAP]" type:"lvm" file_system:"/dev/mapper/centos-swap"

mounted:"/" type:"lvm" file_system:"/dev/mapper/centos-root"


below is my df -h output
which is stored in
FILE1=/tmp/d4 file as below

Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 176M 1.7G 10% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 57G 48G 9.3G 84% /
/dev/sda1 497M 217M 281M 44% /boot
tmpfs 379M 0 379M 0% /run/user/0

simultaneously i want to read another file which contains df -h ouput. and want to compare the Filesystem field with $NAME field in above ouput
if both are same then i want to add remaining fields of df -h output to current ouput

Example :
if file_system:"/dev/mapper/centos-root" is equal to df -h ouput "/dev/mapper/centos-root"

then for the current ouput
mounted:"/" type:"lvm" file_system:"/dev/mapper/centos-root" i want to add remaining df -h field output.

desired output :
mounted:"/" type:"lvm" file_system:"/dev/mapper/centos-root" Avail:"9.3G " Use%:"84%"

used below script :

#!/bin/bash
FILE=/tmp/d5
FILE1=/tmp/d4
while read LINE;
do . <(echo $LINE)
if [ "$MOUNTPOINT" != "" ]

mounted=$MOUNTPOINT

file_system=$NAME
type=$TYPE


while read LINE1;
do . <(echo $LINE1)

File_System=$Filesystem
if [ "$MOUNTPOINT" == "$Filesystem" ];then

echo -e "mounted:$MOUNTPOINT type:$type file_system:$Filesystem avail:$Avail \n"

done < FILE1

fi
fi
done < $FILE


./zzz: line 22: syntax error near unexpected token `done'
./zzz: line 22: `done < FILE1'

Last edited by balu1234; 10-31-2019 at 01:43 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help required on joining one line above & below to the pattern matched string line.

Hi Experts, Help needed on joining one line above & below to the pattern matched string line. The input file, required output is mentioned below Input file ABCD DEFG5 42.0.1-63.38.31 KKKK iokl IP Connection Available ABCD DEFG5 42.0.1-63.38.31 ... (7 Replies)
Discussion started by: krao
7 Replies

2. Shell Programming and Scripting

print range of lines matching pattern and previous line

Hi all, on Solaris 10, I'd like to print a range of lines starting at pattern but also including the very first line before pattern. the following doesn't print the range starting at pattern and going down to the end of file: cat <my file> | sed -n -e '/<pattern>{x;p;}/' I need to include the... (1 Reply)
Discussion started by: siriche
1 Replies

3. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

4. Shell Programming and Scripting

grep based on pattern in a line and print the column before that

$ cat file.log Message Number = : Sending message 10:50:16^|^reqhdr.dummyid^=^02^|^reqhdr.timezone^=^GMT+05:30^|^DUMMYREQUEST^=^BH||||||||||||||||||$BD|OL|C|V||DummyAcctNo|02||24/12/2011|ST_DDM|DDM||||||||reqUUID110612105016$BT||||||||||||||||||$] Length I have the above line in the... (4 Replies)
Discussion started by: kalidass
4 Replies

5. Shell Programming and Scripting

Sed print range of lines between line number and pattern

Hi, I have a file as below This is the line one This is the line two <\XMLTAG> This is the line three This is the line four <\XMLTAG> Output of the SED command need to be as below. This is the line one This is the line two <\XMLTAG> Please do the need to needful to... (4 Replies)
Discussion started by: RMN
4 Replies

6. Shell Programming and Scripting

awk print pattern match line and following lines

Data: Pattern Data Data Data Data Data Data Data Data Data ... With awk, how do I print the pattern matching line, then the subsequent lines following the pattern matching line. Varying number of lines following the pattern matching line. (9 Replies)
Discussion started by: dmesserly
9 Replies

7. Shell Programming and Scripting

Reading line by line from live log file using while loop and considering only those lines start from

Hi, I want to read a live log file line by line and considering those line which start from time stamp; Below code I am using, which read line but throws an exception when comparing line that does not contain error code tail -F /logs/COMMON-ERROR.log | while read myline; do... (2 Replies)
Discussion started by: ketanraut
2 Replies

8. Shell Programming and Scripting

Print lines based on line number and specified condition

Hi, I have a file like below. 1,2,3,4,5,6,7,8,9I would like to print or copied to a file based of line count in perl If I gave a condition 1 to 3 then it should iterate over above file and print 1 to 3 and then again 1 to 3 etc. output should be 1,2,3 4,5,6 7,8,9 (10 Replies)
Discussion started by: Anjan1
10 Replies

9. Shell Programming and Scripting

Match Pattern and print pattern and multiple lines into one line

Hello Experts , require help . See below output: File inputs ------------------------------------------ Server Host = mike id rl images allocated last updated density vimages expiration last read <------- STATUS ------->... (4 Replies)
Discussion started by: tigerhills
4 Replies

10. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies
DM(4)							   BSD Kernel Interfaces Manual 						     DM(4)

NAME
dm -- Device-mapper disk driver SYNOPSIS
pseudo-device dm DESCRIPTION
The dm driver provides the capability of creating one or more virtual disks based on the target mapping. This document assumes that you're familiar with how to generate kernels, how to properly configure disks and pseudo-devices in a kernel con- figuration file, and how to partition disks. This driver is used by the Linux lvm2tools to create and manage lvm in NetBSD. Currently, the linear, zero, and error targets are implemented. Each component partition should be offset at least 2 sectors from the begin- ning of the component disk. This avoids potential conflicts between the component disk's disklabel and dm's disklabel. In i386 it is offset by 65 sectors, where 63 sectors are the initial boot sectors and 2 sectors are used for the disklabel which is set to be read-only. In order to compile in support for dm, you must add a line similar to the following to your kernel configuration file: pseudo-device dm #device-mapper disk device dm may create linear mapped devices, zero, and error block devices. Zero and error block devices are used mostly for testing. Linear devices are used to create virtual disks with linearly mapped virtual blocks to blocks on real disk. dm Device-mapper devices are controlled through the /dev/mapper/control device. For controlling this device ioctl(2) calls are used. For the implementation of the communication channel, the proplib(3) library is used. The protocol channel is defined as a proplib dictionary with needed values. For more details, look at sys/dev/dm/netbsd-dm.h. Before any device can be used, every device-mapper disk device must be initialized. For initialization one line must be passed to the kernel driver in the form of a proplib dictionary. Every device can have more than one table active. An example for such a line is: 0 10240 linear /dev/wd1a 384 dm The first parameter is the start sector for the table defined with this line, the second is the length in sectors which is described with this table. The third parameter is the target name. All other parts of this line depend on the chosen target. dm For the linear target, there are two additional parameters: The first parameter describes the disk device to which the device-mapper disk is mapped. The second parameter is the offset on this disk from the start of the disk/partition. SEE ALSO
config(1), proplib(3), MAKEDEV(8), dmsetup(8), fsck(8), lvm(8), mount(8), newfs(8) HISTORY
The device-mapper disk driver first appeared in NetBSD 6.0. AUTHORS
Adam Hamsik <haad@NetBSD.org> implemented the device-mapper driver for NetBSD. Brett Lymn <blymn@NetBSD.org>, Reinoud Zandijk <reinoud@NetBSD.org>, and Bill Stouder-Studenmund <wrstuden@NetBSD.org> provided guidance and answered questions about the NetBSD implementation. BUGS
This driver is still work-in-progress--there can be bugs. BSD
August 30, 2008 BSD
All times are GMT -4. The time now is 06:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy