Tuesday, 28 March 2017

sed delete/insert/replace


101. How to delete lines using sed?
delete line 1-3
sed -i '1,3d' test.txt
delete line 2,5,8
sed -i '2d;5d;8d' testComparesllequ*.ll

Remove the line containing the string "awk," by using:
sed '/awk/d' filename.txt
sed -i '/; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py/d'

102. How to insert a line using sed?
sed -i  '1 i\
; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu testComparesiequ*.ll

103. sed replace a line:
sed 's/hello/bonjour/' greetings.txt
 Replacing in-place -i
sed ships with the -i flag. Let’s consult man sed:
sed -i 's/hello/bonjour/' greetings.txt

Monday, 27 March 2017

How to open vim and go to a specific line?


add +NUMBER after the vim file command, like:
 vim test/jtony.ll  +123
 This will open file  test/jtony.ll and goto line 123.

Friday, 24 March 2017

awk practice

$ cat /home/sfertile/bin/capture_dot
#!/bin/bash

grep Writing | awk -F\' '{print $2}'



This script grep the lines that contains "Writing" and then split the lines into different columns using the ' symbol seperator, and print the second element after splitting. 

It is equivalent to :
grep Writing | awk -F "'"  '{print $2}'

if we ignore, -F, the default separator will be space.