I am trying to convert the output of
ps awux
into 11 fields with the headers eliminated and then importing that output into an existing table in SQL.
for line in $(ps auwx | sed -e 's/\ \+/\",\"/g'); do
echo "insert into tbl_name values(\"$line\")";
done | mysql
awk
script you're probably going to have to break this out into a real scripting language.
You can remove the first line with sed 1d
You can create the values list with
sql=$(
echo "$line" | sed "
s/'/''/g
s/[[:space:]]\+/','/ # 1
s/[[:space:]]\+/','/ # 2
s/[[:space:]]\+/','/ # 3
s/[[:space:]]\+/','/ # 4
s/[[:space:]]\+/','/ # 5
s/[[:space:]]\+/','/ # 6
s/[[:space:]]\+/','/ # 7
s/[[:space:]]\+/','/ # 8
s/[[:space:]]\+/','/ # 9
s/[[:space:]]\+/','/ # 10
s/^/INSERT INTO table_name VALUES ('/
s/$/');/
"
)