WebJan 21, 2024 · To search a file for a text string, use the following command syntax: $ grep string filename For example, let’s search our document.txt text document for the string “example.” $ grep example document.txt … Web#!/bin/bash max=-1 while IFS= read -r line; do [ [ $ {#line} -gt $max ]] && max=$ {#line} done < "$1" echo "longest line is $max chars long" This idiom is used to read the line exactly verbatim: IFS= read -r line Demo: create a file with leading/trailing whitespace and a backslash $ echo ' h\bHello ' > file
How to Use the find Command in Linux - How-To Geek
WebOct 31, 2016 · Assuming the Length values in the FASTA headers are correct, I would extract them from there: sed -nre 's/^>.*_Length_ ( [0-9]+) .*/\1/p' \ then sort them numerically sort -n \ then output the first and last line sed -ne '1p;$p' In one statement: sed -nre 's/^>.*Length_ ( [0-9]+) .*/\1/p' sort -n sed -ne '1p;$p' WebI think my biggest problem now will be the length of the line in question (2,096,772 chars) and the sheer size of the file (~314Mb). I may see if re-arranging the regex helps speed thing up a bit. Thanks for pointing me in the right direction - I thought their *must* be a way to do it with grep (rather than find which I initially wrote by ... city of tucson emergency broadband benefit
Wc Command in Linux (Count Number of Lines, Words, and …
WebMar 24, 2024 · find . -type f -maxdepth 1 -exec awk 'FNR==2 {print FILENAME,length; nextfile}' {} + -maxdepth 1 makes find non-recursive (i.e. it does not look into subdirectories). You can also use -prune if -maxdepth is not available. Share Improve this answer Follow answered Mar 24, 2024 at 16:51 Quasímodo 18.2k 3 33 72 Add a comment 4 WebSep 24, 2024 · The first command finds all lines in files in the directory containing "ER" (you only need the -R option if you have subdirectories, otherwise the glob * is all you need), removes the lines with Cheese, and then finds the longest of those lines with the wc … WebMar 15, 2024 · Based on the command: find -exec basename ' {}' ';'. which prints recursively only the filenames of all the files starting from the directory you are: all the filenames. This bash line will provide the file with longest name and the its number of characters: Note that the loop involved will make the process slow. city of tucson employee