Sponsored Content
Top Forums Shell Programming and Scripting [bash] remove some entries from output Post 303027015 by apmcd47 on Friday 7th of December 2018 04:53:50 AM
Old 12-07-2018
You need jq installed for this. The maintainers describe jq as a sed-like tool for json files.
Code:
$ sudo lshw -class disk -json | jq -c . | grep size | jq '{product,logicalname,size}'
{                         
  "product": "Backup+  Desk",
  "logicalname": "/dev/sda",
  "size": 3000592977920
}
{
  "product": "Micron_M510_2.5_",
  "logicalname": "/dev/sdb",
  "size": 256060514304
}

The first instance of jq minimises the output to one device per line. sed is then used to reduce the output to only devices with a size field. jq is used once again to pull out the product name, logical name and size for each remaining device. You can then use awk or some other tool to reformat the output into something more palatable, if you desire.

jq will probably be in your Linux repository and should be easy to install.

Andrew
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Why generate "ash and bash" different output for same bash script?

Hi, For my bash script, terminal with bash is generate an OK output and program works right. already, terminal with ash have "line 48: syntax error: Bad substitution" output and program don't work. :confused: (0 Replies)
Discussion started by: s. murat
0 Replies

2. Shell Programming and Scripting

Compare entries in two files, output one of them in bash

I have two files which are of the following format: File1: Unnamed Unnamed Boston Unnamed New_York Unnamed File2: San_Francisco Chicago Portland Austin Orlando Los_Angeles In the case where an entry in File1 is "Unnamed", I want to output the name from the same line in File2.... (5 Replies)
Discussion started by: forthekill
5 Replies

3. Shell Programming and Scripting

Selective remove awk-bash

Hi I have a folder that contain up to 1000 subfolder. Genereally i need just 2 or 3 of them and i can know apriori the name of the subfolder i want to keep. I'd like to erase all the unnecessary subfolders. I've tried with: ls -l | awk '$8 !~ /name_fold/{print "rm -r " $8}'| sh and it... (4 Replies)
Discussion started by: Dedalus
4 Replies

4. Shell Programming and Scripting

remove ] followed by newline in bash

I need to remove ] followed by newline character to convert lines like: line1] line2 into: line1line2 (4 Replies)
Discussion started by: locoroco
4 Replies

5. Shell Programming and Scripting

How to remove comments from a bash script?

I would like to remove comments from a bash script. In addition, I would like to remove lines that consist of only white spaces, and to remove blank lines. #!/bin/bash perl -pe 's/ *#.*$//g' $1 | grep -v ^]*$ | perl -pe 's/ +/ /g' > $2 # # $1 INFILE # $2 OUTFILE The above code... (10 Replies)
Discussion started by: LessNux
10 Replies

6. Shell Programming and Scripting

How to remove '^[[00m' in bash file?

Hi, This should be a simple one: I run the following commands in bash and ksh respectively but got differenant results: # ls -l /var/log > /tmp/a # vi /tmp/a In bash shell, I got: ^ In ksh, I got: total 828552 -rw-r----- 1 root root 189 Aug 9 00:00 acpid -rw-r----- 1 root... (7 Replies)
Discussion started by: aixlover
7 Replies

7. Shell Programming and Scripting

bash - remove duplicates

I need to use a bash script to remove duplicate files from a download list, but I cannot use uniq because the urls are different. I need to go from this: http://***/fae78fe/file1.wmv http://***/39du7si/file1.wmv http://***/d8el2hd/file2.wmv http://***/h893js3/file2.wmv to this: ... (2 Replies)
Discussion started by: locoroco
2 Replies

8. Shell Programming and Scripting

Bash, remove numbers after colon

Hello All, I was wondering if someone might know how to do this. I have a word list that is format like the example below. I need to take away the :number after that... is there some kind of command I could use to remove them? 123456:5562 password:1507 123456789:989 qwerty:877... (7 Replies)
Discussion started by: 3therk1ll
7 Replies

9. Shell Programming and Scripting

Bash - remove duplicates without sort

I need to use bash to remove duplicates without using sort first. I can not use: cat file | sort | uniq But when I use only cat file | uniq some duplicates are not removed. (4 Replies)
Discussion started by: locoroco
4 Replies

10. UNIX for Beginners Questions & Answers

Bash to remove find and remove specific extension

The bash below executes and does find all the .bam files in each R_2019 folder. However set -x shows that the .bam extension only gets removed from one .bam file in each folder (appears to be the last in each). Why is it not removing the extension from each (this is $SAMPLE)? Thank you :). set... (4 Replies)
Discussion started by: cmccabe
4 Replies
MKFS.MINIX(8)						Linux System Administrator's Manual					     MKFS.MINIX(8)

NAME
mkfs.minix - make a Linux MINIX filesystem SYNOPSIS
mkfs.minix [-c|-l filename] [-n namelength] [-i inodecount] [-v] device [size-in-blocks] DESCRIPTION
mkfs.minix creates a Linux MINIX file-system on a device (usually a disk partition). The device is usually of the following form: /dev/hda[1-8] (IDE disk 1) /dev/hdb[1-8] (IDE disk 2) /dev/sda[1-8] (SCSI disk 1) /dev/sdb[1-8] (SCSI disk 2) The size-in-blocks parameter is the desired size of the file system, in blocks. It is present only for backwards compatibility. If omit- ted the size will be determined automatically. Only block counts strictly greater than 10 and strictly less than 65536 are allowed. OPTIONS
-c Check the device for bad blocks before creating the file system. If any are found, the count is printed. -n namelength Specify the maximum length of filenames. Currently, the only allowable values are 14 and 30. The default is 30. Note that kernels older than 0.99p7 only accept namelength 14. -i inodecount Specify the number of inodes for the filesystem. -l filename Read the bad blocks list from filename. The file has one bad block number per line. The count of bad blocks read is printed. -v Make a Minix version 2 filesystem. EXIT CODES
The exit code returned by mkfs.minix is one of the following: 0 No errors 8 Operational error 16 Usage or syntax error SEE ALSO
mkfs(8), fsck(8), reboot(8) AVAILABILITY
The mkfs.minix command is part of the util-linux-ng package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/. Util-linux 2.6 2 July 1996 MKFS.MINIX(8)
All times are GMT -4. The time now is 08:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy